W3C home > Mailing lists > Public > www-forms@w3.org > February 2006

Re: Generic unique path to root?

From: Swithun Crowe <swithun@swithun.servebeer.com>
Date: Mon, 13 Feb 2006 12:22:42 +0000 (GMT)
To: Flinton Adam <Adam.Flinton@cfh.nhs.uk>
cc: www-forms@w3.org
Message-ID: <Pine.LNX.4.64.0602131159380.7214@shadrach.swithun.servebeer.com>

Hello

FA Basically what we're needing is a function which can write out an xpath
FA from the current node back to the root with all attributes present
FA expressed (to give us guaranteed uniqueness).

Is something like:

  <xsl:template match="*" mode="xpath">
    <!-- process parent before current node -->
    <xsl:apply-templates select="parent::*" mode="xpath"/>
    <!-- step and name of node -->
    <xsl:value-of select="concat('/', name())"/>
    <!-- position of node -->
    <xsl:value-of 
        select="concat('[', 
                count(preceding-sibling::*[name()=name(current())]) + 1,
                ']')"/>
    <!-- node attributes -->
    <xsl:apply-templates select="@*" mode="xpath"/>
  </xsl:template>
  
  <xsl:template match="@*" mode="xpath">
    <xsl:variable name="apos">'</xsl:variable>
    <xsl:value-of select="concat('[@', name(), '=', $apos, ., $apos, ']')"/>
  </xsl:template>

what you want? The second template isn't strictly needed if you use the 
count of preceding-siblings with the same name. Then again, if the 
attributes will give a unique path, then you don't need the position 
specified.

Swithun.
Received on Monday, 13 February 2006 12:21:56 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:22:03 GMT