Name

current()

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

Syntax

[1.0] node-set current()
[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 ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.