home contribute faq download

FunctX XSLT Functions

functx:is-descendant

Whether an XML node is a descendant of another node

Google
Webxsltfunctions.com

Description

The functx:is-descendant function returns a boolean value indicating whether $node1 is a descendant of $node2.

Arguments and Return Type

NameTypeDescription
$node1 node() the first node
$node2 node() the second node
return value xs:boolean

XSLT Function Declaration

See XQuery definition.
XSLT 2.0 Syntax:
<xsl:function name="functx:is-descendant" as="xs:boolean"
              xmlns:functx="http://www.functx.com" >
  <xsl:param name="node1" as="node()"/>
  <xsl:param name="node2" as="node()"/>

  <xsl:sequence select="
   boolean($node2 intersect $node1/ancestor::node())
 "/>

</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>
XSLT ExampleResults
functx:is-descendant(
     $in-xml//author[1]/fName,
     $in-xml//author[1])
true
functx:is-descendant(
     $in-xml//author[1],
     $in-xml//author[1]/fName)
false
functx:is-descendant(
     $in-xml//author[1]/fName/text(),
     $in-xml//author[1]/fName)
true
functx:is-descendant(
     $in-xml//author[1],
     $in-xml//author[2])
false

See Also

functx:is-ancestorWhether an XML node is an ancestor of another node

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XSLT Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley