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
9.87Mb 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

A Family Reunion by Jackson, Brenda
Waiting for Rain by Susan Mac Nicol
Inside Straight by Banks, Ray
S.E.C.R.E.T by L. Marie Adeline
B00XXAC6U6 EBOK by Caris Roane
Whatever It Takes by JM Stewart
Bloods Gem by Gloria Conway
Outward Borne by R. J. Weinkam