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>


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 -->
                count(preceding-sibling::*[name()=name(current())]) + 1,
    <!-- node attributes -->
    <xsl:apply-templates select="@*" mode="xpath"/>
  <xsl:template match="@*" mode="xpath">
    <xsl:variable name="apos">'</xsl:variable>
    <xsl:value-of select="concat('[@', name(), '=', $apos, ., $apos, ']')"/>

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 

Received on Monday, 13 February 2006 12:21:56 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:16 UTC