fn:distinct-values

Return sequence with distinct values.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

fn:distinct-values(atomicValue* $srcval) => atomicValue
fn:distinct-values(atomicValue* $srcval, string $collation) => atomicValue

Description

This function returns the sequence that contains each value at most once by removing from $srcval all but one of a set of equal values. All the values must be of a single type or one if its subtypes; numeric values are promoted to a single common type. Equality must be defined for the type. If the values are string values, then equality is determined according to the collation used. If the values are of type xs:double or xs:float, the values "0.0" and "-0.0" are considered equal. If values are of type xs:date or xs:time and have no timezone information, an implicit timezone is provided by the evaluation context.

If the argument is the empty sequence, the function returns the empty sequence.

You can use an optional collation argument which is used when string comparison is required.

Arguments

$srcval

atomic value

$collation

valid collation string literal

Examples

  • The following query results only one value of type xs:time, since both values are equal:

    distinct-values((xs:time("10:00:00"), xs:time("11:00:00+01:00")))
  • The following query results in a type error, since the values of the sequence are not of a single common type:

    distinct-values((1, "one"))
  • Get the names of all doctors, each of them appearing only once in the resulting sequence:

    let    $a := input()/doctor/name/surname
    return distinct-values($a)