xsl:number
Outputs the sequential number of a node in the source document.
Category: instruction
Content: none
Permitted parent elements:
any XSLT element whose content model is
sequence-constructor; any literal result element
Attributes
|
|
Used to format a number obtained from an
expression. If this attribute is present, the |
||||||||||||
|
|
If present, this is an expression that
selects the node to be numbered. The default is |
||||||||||||
|
|
Defines the rules for calculating a number.
The default is |
||||||||||||
|
|
Pattern indicating which nodes to count; the default is to match all nodes of the same type and name as the current node. |
||||||||||||
|
|
Pattern whose exact meaning depends on the level. The calculation is as follows:
|
||||||||||||
|
|
Controls the output format. This contains an alternating sequence of format-tokens and punctuation-tokens. A format-token is any sequence of alphanumeric characters, a punctuation-token is any other sequence. The following values (among others) are supported for the format-token:
There is also support for various Japanese sequences (Hiragana, Katakana, and Kanji) using the format tokens あ, ア, い, イ, 一, and for Greek and Hebrew sequences. The format token "w" gives the sequence "one", "two", "three", ... , while
"W" gives the same in upper-case, and "Ww" in title case. The language is
determined by the The default format is "1". A sequence of Unicode digits other than ASCII digits (for exaple, Tibetan digits) can be used, and will result in decimal numbering using those digits. Similarly, any other character classified as a letter can be used, and will result in "numbering" using all consecutive Unicode letters following the one provided. For example, specifying "x" will give the sequence x, y, z, xx, xy, xz, yx, yy, yz, etc. Specifying the Greek letter alpha (²) will cause "numbering" using the Greek letters up to "Greek letter omega with tonos" (Î). Only "i" and "I" (for roman numbering), and the Japanese characters listed above, are exceptions to this rule. Successive format-tokens in the format are used to process successive numbers in the list. If there are more format-tokens in the format than numbers in the list, the excess format-tokens and punctuation-tokens are ignored. If there are fewer format-tokens in the format than numbers in the list, the last format-token and the punctuation-token that precedes it are used to format all excess numbers, with the final punctuation-token being used only at the end. This character may be preceded or followed by arbitrary punctuation (anything other than these characters or XML special characters such as "<") which is copied to the output verbatim. For example, the value 3 with format "(a)" produces output "(c)". |
||||||||||||
|
|
Specifies which language's conventions are
used when numbering sequences are language-sensitive (for instance the sequence
selected by the tokens "w", "W" and "Ww"), for example |
||||||||||||
|
|
Disambiguates between numbering
sequences that use letters, since in many languages there are two commonly used
systems. The value |
||||||||||||
|
|
Indicates whether cardinal or ordinal numbers are required. |
||||||||||||
|
|
New in XSLT 3.0. Allows numbering to start at a number other than one. Since 9.7, this can be a sequence of integers. |
||||||||||||
|
|
Specifies the grouping separator (for example, thousands) used in decimal numbering sequences. |
||||||||||||
|
|
Specifies the size of the grouping
used in decimal numbering sequences (for example, the value |
Notes on the Saxon implementation
The attribute start-at
is new in XSLT 3.0 and implemented since
Saxon 9.5.
Saxon-EE 9.8 contains a new optimization of <xsl:number level="any">
, based
on XSLT 3.0 accumulators. Provided the parameters of the instruction are context-free (and with
various other conditions, for example the nodes being numbered must not be attributes or namespaces),
Saxon will evaluate the sequence numbers using an accumulator, which means that all the nodes
in a document are numbered in a single pass, rather than each execution of xsl:number
requiring a backwards search through the document.
In XSLT 3.0 some of the capabilities of the xsl:number
instruction -
specifically the formatting capabilities - are more conveniently packaged via
the new format-integer() function, which is also available in XPath and
XQuery.
Details
With large numbers, the digits may be split into groups. For example, specify
grouping-size="3"
and grouping-separator="/"
to
have the number 3000000 displayed as "3/000/000".
Negative numbers are always output in conventional decimal notation, regardless of the format specified.
Examples
Example 1
Format examples:
Number(s) |
Format |
Result |
3 |
(1) |
(3) |
12 |
I |
XII |
2,3 |
1.1 |
2.3 |
2,3 |
1(i) |
2(iii) |
2,3 |
1. |
2.3. |
2,3 |
A.1.1 |
B.3. |
2,3,4,5 |
1.1 |
2.3.4.5 |
Example 2
The following outputs the title child of an <H2>
element
preceded by a composite number formed from the sequential number of the
containing <H1>
element and the number of the containing
<H2>
element.