Name
current() Function — Returns a node-set that has the current node as its only member.
Synopsis
node-setcurrent()
Inputs
None.
Output
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. These two XSLT elements have the same meaning:
<xsl:value-of select="current()"/> <xsl:value-of select="."/>
Within a predicate expression, however, the current node and the context node are usually different. The example section that follows illustrates when you need to use the current() function.
Defined in
XSLT section 12.4, Miscellaneous Additional Functions.
Example
We’ll use the current() function along with a lookup table. Here’s the document we’ll transform:
<?xml version="1.0"?>
<report>
<title>Miles Flown in 2001</title>
<month sequence="01">
<miles-flown>12379</miles-flown>
<miles-earned>35215</miles-earned>
</month>
<month sequence="02">
<miles-flown>32857</miles-flown>
<miles-earned>92731</miles-earned>
</month>
<month sequence="03">
<miles-flown>19920</miles-flown>
<miles-earned>76725</miles-earned>
</month>
<month sequence="04">
<miles-flown>18903</miles-flown>
<miles-earned>31781</miles-earned>
</month>
</report>Here’s our stylesheet. We’ll do the same transform twice, one time with the current() function and one time without it:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:months="Lookup table for month names"> <months:name sequence="12">December</months:name> ...
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