Complete XSLT Element Reference Manual
Definition and Usage
The element is used to determine the integer position of the current node in the source. It is also used to format numbers.
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 | Value | Description |
|---|---|---|
| count | expression | Optional. An XPath expression that specifies which nodes to count. |
| level | single multiple any | Optional. Controls how numbering is allocated. Possible values: * single (default) * multiple * any (Not supported by Netscape 6) |
| from | expression | Optional. An XPath expression that specifies where to start counting. |
| value | expression | Optional. Specifies a user-provided number to use instead of the generated number. |
| format | formatstring | Optional. Defines the output format for the number. Possible values: * format="1" Result: 1 2 3 ... * format="01" Result: 01 02 03 (Not supported by Netscape 6) * format="a" Result: a b c ... (Not supported by Netscape 6) * format="A" Result: A B C... (Not supported by Netscape 6) * format="i" Result: i ii iii iv ... (Not supported by Netscape 6) * format="I" Result: I II III IV ... (Not supported by Netscape 6) |
| lang | languagecode | Optional. Specifies the alphabet table for numbering in the specified language. (Not supported by Netscape 6) |
| letter-value | alphabetic traditional | Optional. Specifies whether numbering in the selected language should be an alphabetical sequence ("alphabetic") or another sequence ("traditional"). The value "alphabetic" specifies an alphabetical sequence; the value "traditional" specifies another sequence. Default is "alphabetic". |
| grouping-separator | character | Optional. Specifies what character to use to separate groups or numbers. Default is a comma. |
| grouping-size | number | Optional. Specifies the number of digits in each group separated by the grouping-separator attribute. Default is 3. |
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
<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>
[
Complete XSLT Element Reference Manual](#)
YouTip