XPath/XQuery distinct-values function


Returns the values that appear in a sequence, with duplicates eliminated.


$arg as xs:anyAtomicType*
) as xs:anyAtomicType*
$arg as xs:anyAtomicType*,
$collation as xs:string
) as xs:anyAtomicType*


The one-argument form of this function is nondeterministic-wrt-ordering, context-dependent, and focus-independent. It depends on collations implicit-timezone.
The two-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on collations static-base-uri implicit-timezone.


The function returns the sequence that results from removing from $arg all but one of a set of values that are considered equal to one another. Two items $J and $K in the input sequence (after atomization, as required by the function signature) are considered equal if fn:deep-equal($J, $K, $coll) is true, where $coll is the collation selected according to the rules in . This collation is used when string comparison is required.

The order in which the sequence of values is returned is implementation-dependent.

Which value of a set of values that compare equal is returned is implementation-dependent.

If the input sequence contains values of different numeric types that differ from each other by small amounts, then the eq operator is not transitive, because of rounding effects occurring during type promotion. In the situation where the input contains three values A, B, and C such that A eq B, B eq C, but A ne C, then the number of items in the result of the function (as well as the choice of which items are returned) is implementation-dependent, subject only to the constraints that (a) no two items in the result sequence compare equal to each other, and (b) every input item that does not appear in the result sequence compares equal to some item that does appear in the result sequence.

For example, this arises when computing:

            xs:double( '1.00000000001'))

because the values of type xs:float and xs:double both compare equal to the value of type xs:decimal but not equal to each other.


The expression fn:distinct-values((1, 2.0, 3, 2)) returns (1, 3, 2.0).

The expression fn:distinct-values((xs:untypedAtomic("cherry"), xs:untypedAtomic("plum"), xs:untypedAtomic("plum"))) returns (xs:untypedAtomic("cherry"), xs:untypedAtomic("plum")).


If $arg is the empty sequence, the function returns the empty sequence.

Values of type xs:untypedAtomic are compared as if they were of type xs:string.

Values that cannot be compared, because the eq operator is not defined for their types, are considered to be distinct.

For xs:float and xs:double values, positive zero is equal to negative zero and, although NaN does not equal itself, if $arg contains multiple NaN values a single NaN is returned.

If xs:dateTime, xs:date or xs:time values do not have a timezone, they are considered to have the implicit timezone provided by the dynamic context for the purpose of comparison. Note that xs:dateTime, xs:date or xs:time values can compare equal even if their timezones are different.