function-available()
FUNCTION: 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.
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"?>
and we name it: xslt_example_current.xml
This example demonstrates how as each individual node is processed by an
xsl:for-each
element it temporarily becomes the current node.
Code for xslt_example_current.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:variable name="staffname" select="devguru_staff/programmer/name" />
<xsl:for-each select="$staffname">
Current node: <xsl:value-of select="
current()
" />
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information