home contribute faq download

FunctX XSLT Functions

functx:path-to-node

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

Google
Webxsltfunctions.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*

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:path-to-node" as="xs:string*"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="nodes" as="node()*"/>

  <xsl:sequence select="
$nodes/string-join(ancestor-or-self::*/name(.), '/')
 "/>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<authors>
   <author>
      <fName>Kate</fName>
      <lName>Jones</lName>
   </author>
   <author>
      <fName>John</fName>
      <lName>Doe</lName>
   </author>
</authors>
</xsl:variable>
XPath 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
Datypic XSLT Services

Recommended Reading:

XQuery