home contribute faq download

FunctX XQuery Functions

functx:is-ancestor

Whether an XML node is an ancestor of another node

Google
Webxqueryfunctions.com

Description

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

Arguments and Return Type

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

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:is-ancestor
  ( $node1 as node() ,
    $node2 as node() )  as xs:boolean {

   exists($node1 intersect $node2/ancestor::node())
 } ;

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

See Also

functx:is-descendantWhether an XML node is a descendant of another node

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