I need a XSLT function which will return me the xpath to the node from which it called.
XML
<root>
<node>
<subnode />
<subnode />
<subnode />
</node>
<node>
<subnode>
<subsubnode >
<xsl:value-of select="fn:generateXPath()" />
</subsubnode >
</subnode>
</node>
</root>
XSL
<xsl:template match="root/node/subnode/sub" >
<xsl:value-of select="fn:generateXPath()" />
</xsl:template>
<xsl:function name="fn:generateXPath" >
<xsl:for-each select="ancestor::*">
<xsl:value-of select="name()" />
</xsl:for-each>
<xsl:value-of select="name()" />
</xsl:function>
I tried with the above function but it throws an error:
XPDY0002: Cannot select a node here: the context item is undefined
But when I tried this in a named template I'm able to get the result. Can this be implemented using xslt:function
.