home contribute faq download

FunctX XQuery Functions

functx:path-to-node-with-pos

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

Google
Webdatypic.com

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

NameTypeDescription
$node 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-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),']'))
 , '/')
 } ;

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

Depends On

functx:index-of-nodeThe position of a node in a sequence, based on node identity

See Also

functx:path-to-nodeA 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, https://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery