Latest web development tutorials

XSLT current () function

XSLT Function Reference objects Complete XSLT Function Reference objects

Definition and Usage

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

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

equal

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

However, a little different. Let's look at the following XPath expression: "catalog / cd". Expression selects the current node <catalog> child node, and then select the <cd> child node <catalog> node. This means that, at each step of the calculation, "." Has a different meaning.

The following line:

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

All cd element values ​​will be equal to the value processing title attribute of the current node's ref attribute.

With this difference:

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

This will deal with title attribute and a ref attribute with the same value for all cd elements.


grammar

node-set current()

Example 1

<?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 the XML file , View the XSL file , view the results .


XSLT Function Reference objects Complete XSLT Function Reference objects