• +49-(0)721-402485-12
Your experts for XML, XQuery and XML Databases

Operations and functions on sequences of atomic values

A sequence of values of xs:integer type can be generated with the to operator. So, the expression

3 to 7

results in the sequence:

(3, 4, 5, 6, 7)

If the first value is equal to the second, a sequence consisiting of only one item is generated. If the first value is greater than the second, the empty sequence is outputted.

It is possible to search a sequence for a certain item. In particular, the fn:index-of() function can return the positions within the sequence which indicate an atomic value being equal to the preset search expression. The equality of character strings can be determined taking account of a sorting order. If the expression is not found, an empty sequence occurs. It should be noted that the first item of a sequence is set to position 1 (not to position 0). The following expression:

fn:index-of((1,0,0,1), 1)

determines all positions of the input sequence on which a 1 is set and therefore returns the sequence:


As you can see in later examples, it is often helpful if dublicates in sequences can be eliminated. This is done by the fn:distinct-values() function which may also be provided with a sorting order for the comparison. The result contains all different values, whereby their order is dependent on the XQuery implementation. If the NaN value occurs several times in the input sequence, it only appears once in the output sequence (although NaN is not always the same as NaN).

$firstval as xs:integer,
$lastval as xs:integer)
as xs:integer*
generates a sequence of integer values which
are between the two values of the parameters
$seq as xdt:anyAtomicType*,
$searchValue as xdt:anyAtomicType[,
$collation as xs:string])
as xs:integer*
returns all positions having an item
which is equal to the searched value
$seq as xdt:anyAtomicType*[,
$collation as xs:string])
as xdt:anyAtomicType*
returns all different values of the
input sequence

Tab. Functions on sequence items


Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)

<< backnext >>