[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Conditional including of attributes

Subject: Conditional including of attributes
From: "Kaarle Kaila" <kaarle.kaila@xxxxxx>
Date: Fri, 26 Mar 2004 10:22:49 +0200
xml perusteet
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.