Description
The functx:path-to-node-with-pos function returns a path to that node, starting with the root element. Specifically, it will concatenate all the names of its ancestors, using a forward slash as a separator. If an element with that name appears more than once in a parent, a predicate is included to indicate the sequence number of that particular node.
Arguments and Return TypeName | Type | Description |
$node |
node()? |
the node sequence |
return value |
xs:string |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:path-to-node-with-pos
( $node as node()? ) as xs:string {
string-join(
for $ancestor in $node/ancestor-or-self::*
let $sibsOfSameName := $ancestor/../*[name() = name($ancestor)]
return concat(name($ancestor),
if (count($sibsOfSameName) <= 1)
then ''
else concat(
'[',functx:index-of-node($sibsOfSameName,$ancestor),']'))
, '/')
} ; |
Exampleslet $in-xml := | <authors>
<author>
<fName>Kate</fName>
<lName>Jones</lName>
</author>
<author>
<fName>John</fName>
<lName>Doe</lName>
</author>
</authors> | return |
XQuery Example | Results |
---|
functx:path-to-node-with-pos(
$in-xml//lName[. = 'Doe']) |
authors/author[2]/lName |
functx:path-to-node-with-pos($in-xml/*[1]) |
authors/author[1] |
Depends OnSee AlsoHistory |
Recommended Reading:
|