home contribute faq download

FunctX XSLT Functions

functx:index-of-deep-equal-node

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

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

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:index-of-deep-equal-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[deep-equal($nodes[$seq],$nodeToFind)]
 "/>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<authors>
   <author>
      <fName/>
      <lName>Smith</lName>
   </author>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>John</fName>
      <lName>Doe</lName>
   </author>
</authors>
</xsl:variable>
<xsl:variable name="anAuthor" as="item()*">
<author>
  <fName>Kate</fName>
  <lName>Jones</lName>
</author>
</xsl:variable>
<xsl:variable name="anotherAuthor" as="item()*">
<author>
  <fName>John</fName>
  <lName>Smith</lName>
</author>
</xsl:variable>
XPath 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, https://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery