current Function

Returns a node set that has the current node as its only member.


          node-set current()

The function returns a node set that has the current node as its only member. For an outermost expression, an expression not occurring within another expression, the current node is always the same as the context node. Thus,

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

is the same as

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

However, within square brackets, the current node is usually different from the context node. For example,

<xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/>

processes all <item> elements that have a <glossary> parent element and a name attribute with value equal to the value of the current node's ref attribute. This is different from

<xsl:apply-templates select="//glossary/item[@name=./@ref]"/>

which means the same as

<xsl:apply-templates select="//glossary/item[@name=@ref]"/>

and so would process all <item> elements that have a <glossary> parent element and that have a name attribute and a ref attribute with the same value.

XML File (current.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="current.xsl" ?>
<nodes>
   <node>first</node>
   <node>1</node>
   <node>
      <obj>class</obj>
   </node>
</nodes>

XSLT File (current.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

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

<xsl:template match="*">
  <blockquote><xsl:apply-templates/></blockquote>
</xsl:template>

</xsl:stylesheet>

Output

The following is the formatted output shown in the browser.

first

1

class

The following is the output from the XSLT processor. To obtain this output, right-click on the browser and select the View XSL Output menu item.

<?xml version="1.0" encoding="UTF-16"?>
<blockquote>
   <blockquote>first</blockquote>
   <blockquote>1</blockquote>
   <blockquote>
      <blockquote>class</blockquote>
   </blockquote>
</blockquote>




Build Date:

2012-08-02
Show: