Expressions that construct sequences
You can use the comma operator to construct sequences.
Comma operators
To construct a sequence
by using the comma operator, specify two or more operands (expressions)
that are separated by commas. When XQuery evaluates
the sequence expression, it evaluates the operands of each comma operator
and concatenates the resulting sequences, in order, into a single
result sequence. For example, the following expression results in
a sequence that contains five integers:
(15, 1, 3, 5, 7)
Restriction: The operands (expressions)
of the comma operator cannot contain an FLWOR expression.
Restriction: XQuery path expressions cannot contain the
comma operator.
A sequence can contain duplicate atomic values and nodes. However, a sequence is never an item in another sequence. When a new sequence is created by concatenating two or more input sequences, the new sequence contains all of the items of the input sequences. The length of the sequence is the sum of the lengths of the input sequences.
Examples: The
following expressions use the comma operator for sequence construction:
- This expression combines four sequences of length one, two, zero,
and two, respectively, into a single sequence of length five. The
result of this expression is the sequence 10, 1, 2, 3, 4.
(10, (1, 2), (), (3, 4))
- The result of this expression is a sequence that contains all
salary
elements that are children of the context node, followed by allbonus
elements that are children of the context node.(salary, bonus)
- Assuming that the variable $price is bound to the value 10.50,
the result of this expression is the sequence 10.50, 10.50.
($price, $price)