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 TypeName | Type | Description |
$node |
node()? |
the node sequence |
return value |
xs:string |
XSLT Function DeclarationSee 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) <= 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 Example | Results |
---|
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 OnSee AlsoHistory |
Recommended Reading:
|