[xsl] Conditional including of attributes

Subject: [xsl] Conditional including of attributes
From: "Kaarle Kaila" <kaarle.kaila@xxxxxx>
Date: Fri, 26 Mar 2004 10:22:49 +0200
hi,

I have in my xml-file an element to make links

<link href="sukbasics.xml" target="main">Perusteet</link>
for html equivalent <a href="sukbasics.xml" target="main">Perusteet</a>

or

<link href="sukbasics.xml">Perusteet</link>
for html equivalent <a href="sukbasics.xml" >Perusteet</a>

The below xslt snippet makes the transformation OK but I don't like it as it
has most it's content twice. Any good advice to make it cleaner would be
appreciated!

---------------
<xsl:template match="link">
<xsl:variable name="lhref" select="@href" />

<xsl:choose>
<xsl:when test="@target>
<a href="{$lhref}" >
<xsl:choose><xsl:when test=".=''"><xsl:value-of select="@href"/></xsl:when>
<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose>
</a>
</xsl:when>
<xsl:otherwise>
<a href="{$lhref}" target="@target">
<xsl:choose><xsl:when test=".=''"><xsl:value-of select="@href"/></xsl:when>
<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

regards
Kaarle

--
Kaarle Kaila
email: kaarle dot kaila at iki dot fi
www.iki.fi/kaila

Current Thread