XSLT current() Function

Definition and Usage

The current() function returns a node set that contains only the current node. Typically, the current node is the same as the context node.

<xsl:value-of select="current()"/>

equals

<xsl:value-of select="."/>

However, there is a difference. Let's look at the following XPath expression: "catalog/cd". The expression selects the <catalog> child node of the current node, and then selects the <cd> child node of the <catalog> node. This means that the "." has a different meaning at each step of the calculation.

The following line:

<xsl:apply-templates select="//cd[@title=current()/@ref]"/>

It will process all cd elements whose title attribute value equals the value of the ref attribute of the current node.

This is different from:

<xsl:apply-templates select="//cd[@title=./@ref]"/>

This will process all cd elements that have the same value for the title attribute and the ref attribute.

Syntax

node-set current()

Example

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
  <xsl:for-each select="catalog/cd/artist">
    Current node: <xsl:value-of select="}}current()"/>
    <br />
  </xsl:for-each>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

View XML File,View XSL File,View Results.