Description
The functx:index-of-deep-equal-node function returns one or more integers representing the position of an XML node within a sequence of nodes. Rather than being based on node identity, it is based on the equality of the name and content of the nodes, as defined by the built-in fn:deep-equal function. If $nodes does not contain a match, the function returns the empty sequence.
Arguments and Return TypeName | Type | Description |
$nodes |
node()* |
the node sequence |
$nodeToFind |
node() |
the node to find in the sequence |
return value |
xs:integer* |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:index-of-deep-equal-node
( $nodes as node()* ,
$nodeToFind as node() ) as xs:integer* {
for $seq in (1 to count($nodes))
return $seq[deep-equal($nodes[$seq],$nodeToFind)]
} ; |
Exampleslet $in-xml := | <authors>
<author>
<fName/>
<lName>Smith</lName>
</author>
<author>
<fName>Kate</fName>
<lName>Jones</lName>
</author>
<author>
<fName>John</fName>
<lName>Doe</lName>
</author>
</authors> | let $anAuthor := | <author>
<fName>Kate</fName>
<lName>Jones</lName>
</author> | let $anotherAuthor := | <author>
<fName>John</fName>
<lName>Smith</lName>
</author> | return |
XQuery Example | Results |
---|
functx:index-of-deep-equal-node(
$in-xml/author,$anAuthor) |
2 |
functx:index-of-deep-equal-node(
$in-xml/author,$anotherAuthor) |
() |
functx:index-of-deep-equal-node(
$in-xml/author/lName,$anAuthor/lName) |
2 |
See AlsoHistory |
Recommended Reading:
|