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 TypeName | Type | Description |
$nodes |
node()* |
the sequence of nodes to test |
return value |
node()* |
the distinct sequence of nodes |
XQuery Function DeclarationSee 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]))]
} ; |
Exampleslet $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 Example | Results |
---|
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 OnSee AlsoHistory |
Recommended Reading:
|