RE: [xsl] <xsl:output method="xml"> and an if sentence to output XML

Subject: RE: [xsl] <xsl:output method="xml"> and an if sentence to output XML
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Mon, 09 May 2005 16:16:59 +0000
Jacob, since you're generating HTML, just use output="html", or even output="xml". Also, tag-writing <xsl:text>&lt;</... is usually not a good idea, and is not needed when generating well-formed elements. Thus the following:


<xsl:template name="outline"> <xsl:param name="title" /> <xsl:text>&lt;dl&gt;</xsl:text> <xsl:text>&lt;dt&gt;</xsl:text> <xsl:value-of select="$title" /> <xsl:text>&lt;/dt&gt;</xsl:text> <xsl:for-each select="outline"> <xsl:choose> <xsl:when test="@this">&lt;dd class="active"&gt;</xsl:when> <xsl:otherwise>&lt;dd&gt;</xsl:otherwise> </xsl:choose> <xsl:text>&lt;a href="</xsl:text> <xsl:value-of select="@url" /> <xsl:text>"&gt;</xsl:text> <xsl:value-of select="@title" /> <xsl:text>&lt;/a&gt;</xsl:text> <xsl:text>&lt;/dd&gt;</xsl:text> </xsl:for-each> <xsl:text>&lt;dl&gt;</xsl:text> </xsl:template>

may be written more simply, and in more XSL-esque fashion as:


<xsl:template name="outline">
	<xsl:param name="title" />

	<dl>
       <xsl:value-of select="$title" />

<xsl:for-each select="outline">
<dd>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@this">active</xsl:when>
</xsl:choose>
</xsl:attribute>
<a>
<xsl:attribute name="href"><xsl:value-of select="@url" /></xsl:attribute>
<xsl:value-of select="@title" />
</a>
</dd>
</xsl:for-each>
</dl>
</xsl:template>


Note containment of elements, and the use of <xsl:attribute/>

regards,

--A

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Current Thread