home contribute faq download

FunctX XQuery Functions

functx:index-of-node

The position of a node in a sequence, based on node identity

Google
Webdatypic.com

Description

The functx:index-of-node function returns one or more integers representing the position of an XML node within a sequence of nodes. It is based entirely on node identity, not the value or content of the nodes.

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-node
  ( $nodes as node()* ,
    $nodeToFind as node() )  as xs:integer* {

  for $seq in (1 to count($nodes))
  return $seq[$nodes[$seq] is $nodeToFind]
 } ;

Examples

let $in-xml :=
<authors>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>John</fName>
      <lName>Doe</lName>
   </author>
</authors>
return
XQuery ExampleResults
functx:index-of-node(
     $in-xml/author,$in-xml/author[1])
1
functx:index-of-node(
     $in-xml/author,$in-xml/author[2])
2
functx:index-of-node(
     $in-xml/author,
     $in-xml/author[lName='Doe'])
2

See Also

functx:index-of-deep-equal-nodeThe position of a node in a sequence, based on contents and attributes

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C XML Query Working Group, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/(parameter names changed for clarity)
Datypic XQuery Services

Recommended Reading:

XQuery