XQuery - distinct-values Function


Advertisements

The distinct-values function is used to get the sequence containing unique items present in a given sequence.

Syntax

distinct-values($seq as item()*)

Input Parameters

  • $seq − provided sequence. A sequence can contain 0 or more items.

Example

XQuery Expression

let $items := (1,2,4,4,5,5)
let $unique-items := distinct-values($items)
return
   <result>   
   
      <items>
      {
         for $item in $unique-items
         return <item>{$item}</item>
      }
      </items>
   
   </result>

Output

<result>
   <items>
      <item>1</item>
      <item>2</item>
      <item>4</item>
      <item>5</item>
   </items>
</result>

Verify the Result

In order to test the above-mentioned functionality, replace the contents of books.xqy (mentioned in Environment Setup chapter) with the above XQuery expression and execute the XQueryTester java program to verify the result.

Print
xquery_sequence_functions.htm
Advertisements