Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XSLT current() function


May 28, 2021 XSL T


Table of contents


XSLT current() function

The role of the XSLT current() function is to return a set of nodes that contain only the current node.


XSLT current() function The complete XSLT function reference object

Definitions and usages

The current() function returns a set of nodes that contain 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. L et's take a look at the following XPath expression: "catalog/cd". T he expression selects the child node of the current node, and then selects the child node of the node. This means that "." has a different meaning at every step of the calculation.

Here's the line:

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

All cd elements that will process the value of the title property equal to the value of the ref property of the current node.

Unlike this one:

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

This handles all cd elements with the same value as the title and ref properties.


Grammar

node-set current()

Instance 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>

XSLT current() function The complete XSLT function reference object