XSLT » Functions » current

node-set = current()

The XSLT current function returns a node-set that only contains the current node. The primary purpose of the current function is to provide a means of accessing the current node when it is not the same as the context node.

Under most circumstances the current node and context node are the same. For example, when using the xsl:value-of element, the current and context nodes are the same. However, when either the xsl:for-each or xsl:apply-templates elements are used to process a selected set of nodes, as each individual node is processed it temporarily becomes the current node.
The context node can always be accessed by using the dot (.) path expression. For example, <xsl:value-of select="." /> will return the context node.
This function has no argument.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:variable name="staffname" select="devguru_staff/programmer/name" />
<xsl:for-each select="$staffname">
Current node: <xsl:value-of select="current()" />
<br />
Current node: Bugs Bunny
Current node: Daisy Duck
Current node: Minnie Mouse
Current node: Pluto
Current node: Porky Pig
Current node: Road Runner

This example demonstrates how as each individual node is processed by an xsl:for-each element it temporarily becomes the current node. This is the code for xslt_example_current.xsl.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_current.xsl"?>

Language(s): XSLT

See Also: