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| Name | Type | Description |
$nodes |
node()* |
the sequence of nodes to test |
| return value |
node()* |
the distinct sequence of nodes |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for July 2004 - January 2007 (1.0): |
|---|
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]))]
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function distinct-deep
( $nodes as node()* ) as node()* {
for $seq in (1 to fn:count($nodes))
return $nodes[$seq][fn:not(functx:is-node-in-sequence-deep-equal(
.,$nodes[fn: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 |
|