distinct-values function

The fn:distinct-values function returns the distinct values in a sequence.

Syntax

Read syntax diagramSkip visual syntax diagramfn:distinct-values( sequence-expression)
sequence-expression
A sequence of atomic values, or the empty sequence.

Returned value

If sequence-expression is not the empty sequence, the returned value is a sequence that contains the distinct values in sequence-expression. Two values, value1 and value2, are distinct if value1 eq value2 is false using the default collation. If the eq operator is not defined for two values, those values are considered to be distinct.

Values of type xdt:untypedAtomic are converted to values of type xs:string before the values are compared.

For xs:float and xs:double values, if sequence-expression contains multiple NaN values, a single NaN value is returned.

For xs:dateTime, xs:date, or xs:time values, the values are adjusted for timezone differences before they are compared. If a value does not have a timezone, the implicit timezone (UTC) is used.

If sequence-expression is the empty sequence, the empty sequence is returned.

If two values in the input sequence are equal by the eq operator but have different types, either of the values, but not both, can appear in the result sequence. The result sequence might not preserve the order of the input sequence.

Example

The following function returns the distinct values in a sequence, after atomizing the nodes in the sequence:

fn:distinct-values((1, 'a', 1.0, 'A', <greeting>Hello</greeting>))

The returned value can be (1, 'a', 'A', 'Hello') or (1.0, 'A', 'a', 'Hello').