I wonder, if there is a way to determine a path to a given source node in xslt. Let's assume the following source XML file:
<one>
<two>
<three/>
<three this="true"/>
</two>
<two>
<three/>
</two>
</one>
I'd like to have a function (custom template) that for node three with attribute this="true" would output something like the following: "1,1,2" - which means: starting from the root go into the first element, then to the first element and then to the second element to reach this particular node.
(the purpouse of this is that i want to have unique identifiers to content that i take from a particular place in the source XML document and transform it to my desired output)
EDIT: i found this:
<xsl:template name="genPath">
<xsl:param name="prevPath"/>
<xsl:variable name="currPath" select="concat('/',name(),'[',
count(preceding-sibling::*[name() = name(current())])+1,']',$prevPath)"/>
<xsl:for-each select="parent::*">
<xsl:call-template name="genPath">
<xsl:with-param name="prevPath" select="$currPath"/>
</xsl:call-template>
</xsl:for-each>
<xsl:if test="not(parent::*)">
<xsl:value-of select="$currPath"/>
</xsl:if>
</xsl:template>
under: How do you output the current element path in XSLT?
With several modification, this will output what i need by putting:
<xsl:call-template name="genPath">
Somewhere, but this way of calling it would output the path to the current node. How to modify it to enable to write a path to a specific child of the current node?
Something like:
<xsl:call-template name="genPath" select="n1:tagname/n1:tagname2">
(i know that the syntax above is incorrect)