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
3.7Mb size Format: txt, pdf, ePub
ads

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:

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

Other books

Learning to Stay by Erin Celello
The Feline Wizard by Christopher Stasheff
Speak of the Devil by Jenna Black
Remember The Moon by Carter, Abigail;
Moth to a Flame by Antoinette, Ashley
Noggin by Whaley, John Corey
The Vampire Diaries: The Salvation: Unspoken by Smith, L. J., Clark, Aubrey