XSLT <xsl:number> element

Definition and Usage

<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.

Grammar

<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 that specifies the nodes to be counted.
level
  • single
  • multiple
  • any

Optional. Controls how the sequence numbers are allocated.

The value can be:

  • single (default)
  • multiple
  • any (Not supported by Netscape 6)
from expression Optional. XPath expression that specifies where to start counting.
value expression Optional. Specifies a user-provided number to replace the generated sequence.
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
  • alphabetic
  • traditional
Optional. Removes ambiguity between number sequences using letters. The value "alphabetic" specifies letter sequences; 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,000,000

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>