|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] How to resolve the absolute location of a node
I'm trying to write a template that would return the absolute location path
of the node i'm processing. e.g. with processing the c elements of
> <a><b x="y"><c/></b><b x="z" p="q"><c/></b></a>
the templete would return
/a/b[1]/c[1] and /a/b[2]/c[1]
Modifying Clark's stylesheet to
<xsl:template name="resolver">
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="concat('/',name())"/>
<xsl:text>[</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>]</xsl:text>
</xsl:for-each>
</xsl:template>
will not do it, since position() "returns a number equal to the context
position from the expression evaluation context" and returns /a[1]/b[2]/c[3]
for both c elements. i've been trying it with recurring templates such as
<xsl:template match="*" mode="resolver">
<xsl:param name="path" select="''"/>
<xsl:choose>
<xsl:when test="parent::*">
<xsl:apply-templates select="parent::*" mode="resolver">
<xsl:with-param name="path">
<xsl:text>/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>[</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>]</xsl:text>
<xsl:value-of select="$path"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:text>/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:value-of select="$path"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
but again this return what i don't want, /a/b[1]/c[1]. has anyone a solution
in their mind?
Jarno
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








