home contribute faq download

FunctX XQuery Functions

functx:distinct-deep

The XML nodes with distinct values, taking into account attributes and descendants

Google
Webdatypic.com

Description

The functx:distinct-deep function compares nodes based on whether they are deep-equal, then returns only the first node with each distinct value. Two nodes are deep-equal if they have the same attributes with the same values, and all the same children, in the same order, that are themselves deep-equal.

Arguments and Return Type

NameTypeDescription
$nodes node()* the sequence of nodes to test
return value node()* the distinct sequence of nodes

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:distinct-deep
  ( $nodes as node()* )  as node()* {

    for $seq in (1 to count($nodes))
    return $nodes[$seq][not(functx:is-node-in-sequence-deep-equal(
                          .,$nodes[position() < $seq]))]
 } ;

Examples

let $in-xml :=
<authors>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>Kate</fName>
      <lName>Doe</lName>
   </author>
</authors>
return
XQuery ExampleResults
functx:distinct-deep($in-xml//author)
<author>
  <fName>Kate</fName>
  <lName>Jones</lName>
</author>
<author>
  <fName>Kate</fName>
  <lName>Doe</lName>
</author>
functx:distinct-deep($in-xml//lName)
<lName>Jones</lName>
<lName>Doe</lName>
functx:distinct-deep($in-xml//fName)
<fName>Kate</fName>

Depends On

functx:is-node-in-sequence-deep-equalWhether an XML node is in a sequence, based on contents and attributes

See Also

functx:is-node-in-sequence-deep-equalWhether an XML node is in a sequence, based on contents and attributes
functx:distinct-nodesThe distinct XML nodes in a sequence (by node identity)
fn:distinct-valuesThe distinct atomic values in a sequence

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, https://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery