xsl-list
[Top] [All Lists]

[xsl] generate xpath expression in web links

2006-08-31 15:59:58
Hello

Our web app needs to generate the XPath expression that uniquely
identifies a particular node, something like:

<a href="/project[1]/admin[3]/project-manager[5]/full-name[2]">Some
Name</a>

This is what I've come up with so far. 

===========================

<a><xsl:call-template name="generatePath"/><xsl:value-of
select="some-link"/></a>

<xsl:template name="generatePath">
        <xsl:attribute name="href">
                <xsl:for-each select="ancestor-or-self::*">
                        <xsl:text>/</xsl:text>
                        <xsl:value-of select="local-name(.)"/>
                        <xsl:text>[</xsl:text>
                        <xsl:value-of
select="count(preceding-sibling::*[local-name()=local-name(current())])+
1"/>
                        <xsl:text>]</xsl:text>
                </xsl:for-each>
        </xsl:attribute>
</xsl:template>

===========================

It works ok, but I just wanted to check to see if I was missing anything
to make it more efficient. I'm using xslt2.

Thanks, David

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] generate xpath expression in web links, David Murphy <=