home contribute faq download

FunctX XSLT Functions

functx:index-of-node

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

Google
Webxsltfunctions.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*

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:index-of-node" as="xs:integer*"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="nodes" as="node()*"/>
  <xsl:param name="nodeToFind" as="node()"/>

  <xsl:sequence select="
  for $seq in (1 to count($nodes))
  return $seq[$nodes[$seq] is $nodeToFind]
 "/>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<authors>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>John</fName>
      <lName>Doe</lName>
   </author>
</authors>
</xsl:variable>
XPath 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 XSLT Services

Recommended Reading:

XQuery