August 2001
Intermediate to advanced
480 pages
11h 16m
English
current() Function — Returns a node-set that has the current node as its only member.
node-setcurrent()
None.
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.
XSLT section 12.4, Miscellaneous Additional Functions.
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> ...