xsl:number
Generates a formatted number — typically for chapter, section, or list numbering.
<xsl:number level="single" count="chapter" format="1. "/>xsl:number either takes a number directly via the value attribute, or computes one by counting nodes that match count from the start of the document or from a from reference point. The format picture controls how the number is rendered.
level="single" counts preceding siblings of the source node that match count. level="multiple" produces hierarchical numbering like 1.2.3 by counting at each ancestor level. level="any" counts every matching node from the start of the document (or from from), useful for footnote numbering.
The format attribute uses standard tokens: 1 for decimal, 01 for zero-padded, a / A for alphabetic, i / I for Roman numerals. Word formatting (w, W, Ww) is not supported. Grouping separators are honored.
Attributes
| Attribute | Description |
|---|---|
value |
XPath expression producing the number directly (bypasses count/from/level). |
select |
XPath expression for the source node (default: context node). |
level |
single (default), multiple, or any. |
count |
Match pattern for nodes to count. |
from |
Match pattern for the reference point to count from. |
format |
Format picture (default: 1). |
grouping-separator |
Separator inserted into long numbers. |
grouping-size |
Group size for grouping-separator. |
lang |
Language for alphabetic formatting. |
Examples
Hierarchical section numbering:
<xsl:template match="section">
<h2>
<xsl:number level="multiple" count="section" format="1.1 "/>
<xsl:value-of select="title"/>
</h2>
</xsl:template>Footnote numbering across the whole document:
<xsl:number level="any" count="footnote" format="[1]"/>Roman numerals:
<xsl:number value="$n" format="I"/>