How to resolve the absolute location of a node

Subject: How to resolve the absolute location of a node
From: "Jarno Elovirta" <jarnose@xxxxxxxxxx>
Date: Sun, 17 Oct 1999 15:21:48 +0300
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


Current Thread