XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (203 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
8.61Mb size Format: txt, pdf, ePub
grouping-separator
optional
Attribute value template returning a single character
A character to be used to separate groups of digits (for example, a comma as a thousand separator).
grouping-size
optional
Attribute value template returning a number
The number of digits in each group, indicating where the grouping-separator should be inserted.

For the syntax of a pattern, see Chapter 12.

Content

None, the element is always empty.

Effect

The

instruction performs four tasks:

1.
Determines a sequence number. This is actually a sequence of integers (to allow section numbers such as 1.16.2); since it is not necessarily a number in the XPath sense, the specification refers to it as the
place marker
.

2.
Analyzes the format string into a sequence of format tokens.

3.
Formats each part of the place marker using the appropriate format token.

4.
Returns the resulting string as a text node.

These steps are considered individually in the following sections.

Determining a Sequence Number

If the
value
attribute is specified, the place marker is obtained by evaluating the expression in the
value
attribute and converting it to a sequence of integers. This is done by atomizing the sequence, calling the
number()
function for each value, applying the
round()
function and then casting to an integer. (This rather cumbersome procedure is chosen largely for backward-compatibility reasons.) If backward-compatibility mode is in effect (that is, if the
version
attribute on the

element or on some other enclosing element is
1.0
), then all items in the sequence after the first are discarded. This is to emulate the behavior of XSLT 1.0.

If the
value
attribute is specified, the
level
,
count
, and
from
attributes must not be specified.

It is a fatal error if the sequence is empty, or if any value in the sequence can't be converted to an integer, or produces an integer less than zero. (In backward-compatibility mode, however, the processor outputs
NaN
instead of reporting the error.) The

element is designed for handling the natural numbers that arise from counting nodes, so if you want to handle other cases, it's better to use the
format-number()
function described in Chapter 13, on page 788.

If no
value
attribute is specified,

determines a place marker based on the position of a node in a source document. When the
select
attribute is present, the node to be numbered is determined by evaluating the expression contained in this attribute; a type error is reported if the result is anything other than a single node. If the
select
attribute is omitted, the instruction operates on the context node. In this case, an error is reported if the context item is not a node. Either way, we will refer to this node as the
start node
.

The rules for determining the place marker (always a sequence of non-negative integers) depend on the value of the
level
,
count
, and
from
attributes. If any of these attributes is omitted, the default is as follows:

Attribute
Default value
level
single
count
A pattern that matches nodes of the same kind as the start node, and with the same name as the start node if it has a name. As always, names with namespace prefixes are matched using the relevant namespace URI rather than the prefix.
from
A pattern that matches the root node of the tree containing the selected node.

If the
level
attribute is
single
or
any
the place marker will normally contain a single integer; if it is
multiple
then it may contain several integers (for example
3.6.1
). It is also possible for the list to be empty.

Other books

Bittersweet Sands by Rick Ranson
The Relic Murders by Paul Doherty
Who bombed the Hilton? by Rachel Landers
A Long Way From You by Gwendolyn Heasley
Losing Control by Jen Frederick
The Stolen by Celia Thomson
The Dublin Detective by J. R. Roberts
Trial Junkies (A Thriller) by Robert Gregory Browne