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 Type| Name | Type | Description |
$node |
node()? |
the node sequence |
| return value |
xs:string |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for July 2004 - January 2007 (1.0): |
|---|
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),']'))
, '/')
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function path-to-node-with-pos
( $node as node()? ) as xs:string {
fn:string-join(
for $ancestor in $node/ancestor-or-self::*
let $sibsOfSameName := $ancestor/../*[fn:name() = fn:name($ancestor)]
return fn:concat(fn:name($ancestor),
if (fn:count($sibsOfSameName) <= 1)
then ''
else fn: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 |
|