Name
current()
Returns a node-set that has the current node as its only member.
Syntax
[1.0] node-setcurrent()[2.0] item()current()
Inputs
None.
Output
[1.0] A node-set that has the current node as its only member. Most of the time, the current node is no different than the context node.
[2.0] This function, used inside an XPath expression, returns the item that was the context item when the expression was invoked.
In XSLT 1.0 and 2.0, the current node/item is almost always the same as the context node/item. For example, the two XPath expressions below are always the same:
<xsl:value-of select="current()"/> <xsl:value-of select="."/>
Within a predicate expression, however, the current node and the context node are usually different.
Defined in
[1.0] XSLT section 12.4, “Miscellaneous Additional Functions.”
[2.0] XSLT section 16.6, “Miscellaneous Additional Functions.”
Example
We’ll use the current() function along with a
lookup table. We’ll transform a modified version of our chocolate
sales figures:
<?xml version="1.0" encoding="utf-8"?>
<!-- chocolate-by-month.xml -->
<report year="2006">
<title>Chocolate bar sales by month</title>
<sales month="08" total="91316"/>
<sales month="09" total="82911"/>
<sales month="10" total="128587"/>
<sales month="11" total="79244"/>
<sales month="12" total="113606"/>
</report>Here’s our stylesheet. It has a lookup table of month names;
we’ll use the lookup table to replace the month attribute with the name of the corresponding month. The stylesheet does the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access