home contribute faq download

FunctX XQuery Functions

functx:path-to-node

A path to an XML node (or sequence of nodes)

Google
Webxqueryfunctions.com

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

NameTypeDescription
$nodes node()* the node sequence
return value xs:string*

XQuery Function Declaration

See XSLT definition.
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(.), '/')
 } ;

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:path-to-node($in-xml//lName[. = 'Doe'])
authors/author/lName
functx:path-to-node($in-xml/*[1])
authors/author

See Also

functx:path-to-node-with-posA unique path to an XML node (or sequence of nodes)
functx:distinct-element-pathsThe distinct paths of all descendant elements in an XML fragment

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley