home contribute faq download

FunctX XSLT 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

XSLT Function Declaration

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

 <xsl:variable name="names" as="xs:string*">
   <xsl:for-each select="$node/ancestor-or-self::*">
     <xsl:variable name="ancestor" select="."/>
     <xsl:variable name="sibsOfSameName"
           select="$ancestor/../*[name() = name($ancestor)]"/>
     <xsl:sequence select="concat(name($ancestor),
         if (count($sibsOfSameName) &lt;= 1)
         then ''
         else concat(
        '[',functx:index-of-node($sibsOfSameName,$ancestor),']'))"/>
   </xsl:for-each>
 </xsl:variable>
 <xsl:sequence select="string-join($names,'/')"/>

</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-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 XSLT Services

Recommended Reading:

XQuery