Description
The functx:path-to-node 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.
Note that it is not necessarily a path that will return just that node. For example, if there are several author element children of authors, and you run the function on author, it will return the path authors/author which will return all of the authors, not just the one you ran the function on. See functx:path-to-node-with-pos for a function that returns a unique path to that element.
Arguments and Return Type| Name | Type | Description |
$nodes |
node()* |
the node sequence |
| return value |
xs:string* |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for April 2005 - January 2007 (1.0): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:path-to-node
( $nodes as node()* ) as xs:string* {
$nodes/string-join(ancestor-or-self::*/name(.), '/')
} ; | | XQuery Syntax for July 2004: |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:path-to-node
( $nodes as node()* ) as xs:string* {
for $node in $nodes
return string-join(for $node in $node/ancestor-or-self::*
return name($node), '/')
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function path-to-node
( $nodes as node()* ) as xs:string* {
for $node in $nodes
return fn:string-join(for $node in $node/ancestor-or-self::*
return fn:name($node), '/')
} |
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($in-xml//lName[. = 'Doe'])
|
authors/author/lName
|
functx:path-to-node($in-xml/*[1])
|
authors/author
|
See AlsoHistory |
|