XSLT » Elements » xsl:number

  format="{ string }"
  grouping-separator="{ character }"
  grouping-size="{ number }"
  lang="{ languagecode }"
  letter-value={ "alphabetic" | "traditional" }
  level="any" | "multiple" | "single"

The xsl:number element has two possible uses. It can determine the sequence number for the current node and it can format a number for display in the output.

The sequence number is the integer position of the current node in a source document (source tree). There are actually three ways that the sequence number can be determined and you can use the level attribute to choose which way.
The formatting process converts either the sequence number or the number provided by the value attribute to a string. By using various attributes of the xsl:number element, you can exert great control over the appearance of the formatted number in the output.
In comparison, the xsl:decimal-format element defines the symbols and characters used by the format-number function to convert numbers to strings.
This is a self-closing element and it cannot contain any child elements or any content.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:for-each select="devguru_staff/programmer">
<xsl:number value="position()" format="1. " />
<xsl:value-of select="name" />
<br />
1. Bugs Bunny
2. Daisy Duck
3. Minnie Mouse
4. Pluto
5. Porky Pig
6. Road Runner 6. Road Runner

This is the code for xslt_example_number.xsl.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_number.xsl"?>

Language(s): XSLT

See Also: