Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
If there is no formatting token, then the same string is used for the prefix and the suffix. So if the format string is
$
, then the number 20 will be formatted as
$20$
.
Formatting the Numbers
This section describes how a single number is formatted using a single formatting token to construct a string that will form part of the final output string.
The XSLT specification defines this process only partially. There are some definitive rules, some guidance for the implementor, and many other cases that are left unspecified.
The definitive cases are listed in the table below.
Formatting token | Output sequence |
1 | 1, 2, 3, 4, . . . |
01 | 01, 02, 03, . . . , 10, 11, 12, . . . More generally, if the format token is 1 preceded by n zeros, the output numbers will be in decimal notation with a minimum of n + 1 digits. |
other Unicode digits | The above two rules also apply to any other Unicode digits equivalent to 0 and 1, for example Thai or Tamil digits. The number is output using the same family of digits as is used in the formatting token. |
a | a, b, c, d, . . . , x, y, z, aa, ab, ac, . . . . |
A | A, B, C, D, . . . , X, Y, Z, AA, AB, AC, . . . . |
i | i, ii, iii, iv, . . . , x, xi, xii, xiii, xiv, . . . |
I | I, II, III, IV, . . . , X, XI, XII, XIII, XIV, . . . |
w | one, two, three, . . . ten, eleven (in the chosen language) |
W | ONE, TWO, THREE, . . . TEN, ELEVEN (in the chosen language) |
Ww | One, Two, Three, . . . Ten, Eleven (in the chosen language) |
The specification doesn't define these sequences in detail, for example it doesn't say whether “twenty-one” is hyphenated, or specify how to represent numbers above 1000 in Roman numerals (the Romans themselves had various conventions, such as putting horizontal lines above the letters, or boxes around them—effects that would be difficult to achieve in XML output). The specification does say, however, that if the number is too large to be formatted as requested, it should be output as if the formatting token were
1
.
In the table above, the sequences are shown starting at one. However, many of the sequences also allow the number zero to be formatted. Zero will never appear in a place marker generated by counting nodes, but it can appear when the number is supplied using the
value
attribute.
The attributes
grouping-separator
and
grouping-size
can be used to control the separation of groups of digits. For example, setting
grouping-separator=“”
(a single space) and
grouping-size=“2”
would cause the number 12345 to be output as
1
23
45
. The groups will always be formed by counting digits from the right-hand side. If either of these attributes is specified, the other should also be specified.