home contribute faq download

FunctX XQuery Functions

functx:index-of-deep-equal-node

The position of a node in a sequence, based on contents and attributes

Google
Webxqueryfunctions.com

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 Type

NameTypeDescription
$nodes node()* the node sequence
$nodeToFind node() the node to find in the sequence
return value xs:integer*

XQuery Function Declaration

See 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)]
 } ;

Examples

let $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 ExampleResults
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 Also

functx:index-of-nodeThe position of a node in a sequence, based on node identity
functx:distinct-deepThe XML nodes with distinct values, taking into account attributes and descendants

History

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

Recommended Reading:

XQuery