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 TypeName | Type | Description |
$arg |
xs:anyAtomicType* |
the sequence of atomic values |
$collation |
xs:string |
the collation to use for comparing strings |
return value |
xs:anyAtomicType* |
Examples<xsl:variable name="in-xml" as="item()*"> | | <in-xml>
<a>3</a>
<b>5</b>
<b>3</b>
</in-xml> |
| </xsl:variable> |
XPath Example | Results |
---|
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 AlsoHistory |
Recommended Reading:
|