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

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

Generally, the automatic sort into document order is a choice that avoids surprises, especially when processing loosely structured text: if an expression selects a number of text nodes in a document, then document order is the order that is most likely to retain the meaning. The only situation that can sometimes be confusing is when you write an expression such as
$sorted-employees/name
where the sequence in
$sorted-employees
has been carefully sorted into some logical order (for example, sorting employees by length of service). You can't do this kind of sorting in XPath alone, but it's easily done in XSLT or XQuery. In this situation, the
/
operator destroys the ordering and gives you the names of the employees in document order. The solution in this case is to use a
for
expression instead of a path expression, as described in Chapter 10.

There is no specific function in XPath to take an existing sequence and reorder it in document order, but you can achieve this easily by writing the dummy path expression
$seq/.
, or if you prefer, by taking the union with an empty sequence:
$seq|()
.

The Binary
 /
Operator

Informally, we could say that a path expression is a sequence of steps separated by
/
or
//
. This is reflected in the syntax rule:

Other books

Talking Heads by John Domini
1 Nothing Bundt Murder by Leigh Selfman
Never Cry Mercy by L. T. Ryan
The Wildlife Games by Bindi Irwin
Olympus Mons by William Walling