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

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.56Mb size Format: txt, pdf, ePub
ads

Although most XPath expressions return nodes in document order, not all do so. For example, the expression
title, author, publisher
returns a sequence containing first the child
title
elements, then the child
author
elements, and then the child
publisher
elements of the context node, regardless of the order that these nodes appear in the source document. The nodes returned by the XPath expression will be processed in the order of the sequence that is returned, not necessarily in document order.

If there are one or more

instructions as children of the

instruction, the selected nodes are sorted before processing. Each

instruction defines one sort key. For details of how sorting is controlled, see

on page 455. If there are several sort keys defined, they apply in major-to-minor order. For example, if the first

defines sorting by country and the second by state, the selected nodes will be processed in order of state within country. If two selected nodes have equal sort keys (or if the same node is included more than once in the sequence), they will be processed in the order that they appeared in the original result of the
select
expression, unless the first

element specifies
stable=“no”
, in which case there are no guarantees.

Choosing a Template Rule

For each node to be processed, a template rule is selected. The choice of a template rule is made independently for each selected node; they may all be processed by the same template rule, or a different template rule may be chosen for each one.

The template rule selected for processing a node will always be either an

element with a
match
attribute, or a built-in template rule provided by the XSLT processor.

An

element will be used to process a node only if it has a matching
mode
: That is, the
mode
attribute of the

element must match the
mode
attribute of the

element. An

element can define a list of modes that it matches, or it can specify
#all
to indicate that it matches all modes. If the

element has no
mode
attribute, or if its
mode
attribute includes the keyword
#default
, then the template rule matches the default mode, which is the mode that is used when

has no
mode
attribute. If the mode name contains a namespace prefix, it is the namespace URI that must match, not necessarily the prefix itself. Alternatively, the

instruction can specify
mode=“#current”
to continue processing in the current mode. This is useful when the instruction is contained in a template rule that can be invoked in a number of different modes. The concept of the
current mode
is explained more fully in the section for

.

Note that if the
mode
attribute is omitted, it makes no difference what mode was originally used to select the template rule containing the

instruction. The mode is not sticky; it reverts to the default mode as soon as

is used with no
mode
attribute. If you want to continue processing in the current mode, either specify the mode explicitly, or set
mode=“#current”
.

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.56Mb size Format: txt, pdf, ePub
ads

Other books

Shroud by John Banville
Freedom Song by Amit Chaudhuri
Spy Princess by Shrabani Basu
Bayou Trackdown by Jon Sharpe
BOMBSHELL by Turner, Xyla
Moon Cursed by Handeland, Lori
The Cradle Will Fall by Mary Higgins Clark
Death Canyon by David Riley Bertsch
The Shark Mutiny by Patrick Robinson