XSLT <xsl:number> Element
Definition and Usage
The <xsl:number> element is used to determine the integer position of the current node in the source. It is also used to insert formatted numbers into the result tree.
Syntax
<xsl:number count="expression" level="single|multiple|any" from="expression" value="expression" format="formatstring" lang="languagecode" letter-value="alphabetic|traditional" grouping-separator="character" grouping-size="number"/>
Attribute
Attribute | Value | Description |
---|---|---|
count | expression | Optional. XPath expression specifying the nodes to be counted. |
level |
|
Optional. Controls how to allocate sequence numbers. The value can be:
|
from | expression | Optional. XPath expression specifying where to start counting. |
value | expression | Optional. Specifies the number provided by the user to replace the generated sequence number. |
format | formatstring | Optional. Defines the output format of the number.Values that can be used. |
lang | languagecode | Optional. Specifies the language alphabet used for numbering. |
letter-value |
|
Optional. Removes ambiguity between numbered sequences using letters. The value "alphabetic" specifies the letter sequence; the value "traditional" specifies other sequences. The default value is "alphabetic". |
grouping-separator | character | Optional. Specifies the character used to separate groups or numbers. The default is a comma. |
grouping-size | number | Optional. Specifies the size of the grouping. The default is 3. |
Format marker
Format marker | Generated sequence |
---|---|
1 | 1 2 3 4 5 ... 10 11 12 ... |
01 | 01 02 03 ... 19 10 11 ... 99 100 101... |
a | a b c . . |
A | A B C ...Z AA AB AC... |
i | i ii iii iv v vi vii viii ix x... |
I | I II III IV V VI VII VIII IX X... |
Note:Netscape 6 does not support the following tags: 01, a, A, i, I.
Instance
Example 1
<xsl:number value="250000" grouping-separator="."/>
Output:
250.000
Example 2
<xsl:number value="250000" grouping-size="2"/>
Output:
25,00,00
Example 3
<xsl:number value="12" grouping-size="1" grouping-separator="#" format="I"/>
Output:
X#I#I
Example 4
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <p> <xsl:for-each select="catalog/cd"> <xsl:number value="position()" format="1" /> <xsl:value-of select="title" /><br /> </xsl:for-each> </p> </body> </html> </xsl:template> </xsl:stylesheet>