Re: [xsl] a href problem with XSLT

Subject: Re: [xsl] a href problem with XSLT
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 27 Jul 2006 13:25:24 +0100
 {generate-id(.) generate id generates a new unique id for the node,
you don't want that, you just want its value, so use {.}

<xsl:template match="dir:directory|dir:file">
<li>
<xsl:value-of select="@name"/>
<xsl:if test="name(.)='dir:directory'">

tests with name() arenot usually a good idea as they are not namespace
aware, also in this case it would be simpler and probably quicker just
to have two templates, since the two cases do different things.

<xsl:for-each select="@name">

there can only be one such attribute so you don't need for-each here
(unless the attribute can be missing)

so...

<xsl:template match="dir:directory">
<li>
<xsl:value-of select="@name"/>
<ul><xsl:apply-templates/></ul>
<a href="{@name}"><xsl:value-of select="@name"/></a>
</li>
</xsl:template>

<xsl:template match="dir:file">
<li>
<xsl:value-of select="@name"/>
<a href="{@name}"><xsl:value-of select="@name"/></a>
</li>
</xsl:template>

Current Thread