June 2008
Intermediate to advanced
986 pages
27h 8m
English
There are some changes to the <xsl:number> element in XSLT 2.0.
First of all, three new formats have been added: w, W, and
Ww. Those formats produce words in
the default language on your machine (there’s also a lang attribute you can use to change the
language). Here’s an example:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:text>Automobile manufacturers and their cars
</xsl:text>
<xsl:for-each select="cars/manufacturer">
<xsl:value-of select="@name"/>
<xsl:text>
</xsl:text>
<xsl:for-each select="car">
<xsl:text> Car </xsl:text>
<xsl:number count="car" level="single" format="w"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>This stylesheet produces this text:
Automobile manufacturers and their cars Chevrolet Car one: Cavalier Car two: Corvette Car three: Impala Car four: Malibu Ford Car one: Pinto Car two: Mustang Car three: Taurus Volkswagen Car one: Beetle Car two: Jetta Car three: Passat Car four: Touraeg
Using the format W produces
the numbers ONE, TWO, THREE, and so forth, while the format
Ww produces One, Two,
Three.
Another difference is the addition of the select attribute. Normally <xsl:number> numbers the current node;
you can use the select attribute to
generate the number for another node.
XSLT 2.0 ...
Read now
Unlock full access