Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The order of the items in the two sequences is retained in the result. This is true even if the operands are nodes: there is no sorting into document order. This means that in XSLT you can use a construct such as:
to process the selected elements in a specified order, regardless of the order in which they appear in the source document. This example is not necessarily processing exactly three elements: there might, for example, be five authors and no abstract. Because the path expression
author
selects the five authors in document order, they will be processed in this order, but they will be processed after the
Examples
Here are some examples of expressions that make use of the
,
operator to construct sequences.
Expression | Effect |
max(($net , $gross)) | Selects whichever of $net and $gross is larger, comparing them according to their actual type (and using the default collation if they are strings). |
for $i in (1 to 4 , 8 , 13) return $seq[$i] | Selects the items at positions 1, 2, 3, 4, 8, and 13 of the sequence $seq . For the meaning of the to operator, see the next section. |
string-join((@a , @b , @c) , “-”) | Creates a string containing the values of the attributes @a , @b , and @c of the context node (in that order), separated by hyphens. |
(@code , “N/A”)[1] | Returns the code attribute of the context node if it has such an attribute, or the string N/A otherwise. This expression makes use of the fact that when the code attribute is absent, the value of @code is an empty sequence, and concatenating an empty sequence with another sequence returns the other sequence (in this case the singleton string N/A ) unchanged. The predicate in square brackets makes this a filter expression: filter expressions are described later in this chapter, on page 637. |
book/(author , title , isbn) | Returns a sequence containing the in document order . Although the , operator retains the order as specified, the / operator causes the nodes to be sorted into document order. So in this case the , operator is exactly equivalent to the union operator | . |