home contribute faq download

FunctX XSLT Functions


The distinct atomic values in a sequence



The fn:distinct-values function returns a sequence of unique atomic values from $arg. Values are compared based on their typed value. Values of different numeric types may be equal, for example the xs:integer value 1 is equal to the xs:decimal value 1.0, so the function only returns one of these values. If two values have incomparable types, e.g. xs:string and xs:integer, they are considered distinct, rather than an error being raised. Untyped values are treated like strings.

The $arg sequence can contain atomic values or nodes, or a combination of the two. The nodes in the sequence have their typed values extracted, using the usual function conversion rules. This means that only the contents of the nodes are compared, not any other properties of the nodes (for example, their names).

Because XQuery does not specify which of the duplicates to exclude, there may be some variation among implementations in the order and type of items in the result sequence.

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

$arg xs:anyAtomicType* the sequence of atomic values
$collation xs:string the collation to use for comparing strings
return value xs:anyAtomicType*


<xsl:variable name="in-xml" as="item()*">
XPath ExampleResults
distinct-values( ('a', 'b', 'a') )
('a', 'b')
distinct-values( (1, 2, 3) )
(1, 2, 3)
distinct-values( ('a', 2, 3) )
('a', 2, 3)
    xs:float('1.0E0') ) )
(3, 5)
distinct-values( () )

See Also

functx:distinct-deepThe XML nodes with distinct values, taking into account attributes and descendants
functx:are-distinct-valuesWhether all the values in a sequence are distinct
functx:non-distinct-valuesReturns any values that appear more than once in a sequence
functx:distinct-nodesThe distinct XML nodes in a sequence (by node identity)


Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XSLT Services

Recommended Reading: