[xquery-talk] Absolute Path of Node

martin martin at x-hive.com
Mon May 30 17:35:21 PDT 2005


Hi,

do it yourself (tm), featuring the famous bib example:

 > declare function path-from-root($x as node()) {
 >   if ($x/parent::*) then
 >     concat( path-from-root($x/parent::*), "/", node-name($x) )
 >   else
 >     concat( "/", node-name($x) )
 > };
 > let $a := doc("bib.xml")//author[1]            (: some node :)
 > return path-from-root($a)

Part 2:
 > let $a := doc("bib.xml")/bib/book[1]/author[1] (: some node :)
 > let $b := doc("bib.xml")/bib/book[1]/title[1]  (: some node :)
 > return (for $x in $a/ancestor-or-self::*
 >         where some $v in $b/ancestor-or-self::* satisfies $v is $x
 >         return $x)[last()]

Regards,
Martin


More information about the talk mailing list