home contribute faq download

FunctX XQuery Functions

fn:distinct-values

The distinct atomic values in a sequence

Google
Webxqueryfunctions.com

Description

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

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

Examples

let $in-xml :=
<in-xml>
  <a>3</a>
  <b>5</b>
  <b>3</b>
</in-xml>
return
XQuery ExampleResults
distinct-values( ('a', 'b', 'a') )
('a', 'b')
distinct-values( (1, 2, 3) )
(1, 2, 3)
distinct-values( ('a', 2, 3) )
('a', 2, 3)
distinct-values(
   (xs:integer('1'),
    xs:decimal('1.0'),
    xs:float('1.0E0') ) )
1
distinct-values($in-xml/*)
(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)

History

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/
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley