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 take a 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 in each step of the calculation, "." has a different meaning.
The following line:
<xsl:apply-templates select="//cd[@title=current()/@ref]"/>
It will process all cd elements where the value of the title attribute is equal to 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 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>