This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: comparing the valie of an attribute..
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] comparing the valie of an attribute..
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Tue, 9 Jan 2001 09:25:37 +0000
- Organization: Jeni Tennison Consulting Ltd
- References: <4B571C0EB6C0D4119C4A00508BF907DA50726D@nyschx19psge.sch.ge.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Sara Mitchell wrote:
> To use xsl:choose, you can do something like this:
>
> <xsl:template match="event">
> <!-- set variable based on the value of type attribute -->
> <xsl:variable name="colortype">
> <xsl:choose>
> <xsl:when test="@type='error'">#990000</xsl:when>
> <xsl:otherwise>#dddddd</xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <td>
> <!-- assign background color using variable -->
> <xsl:attribute name="bgcolor"><xsl:value-of select="$colortype"/>
> </xsl:attribute>
> ...what ever your cell content should be here...
> </td>
> </xsl:template>
There's no particular need to use a variable here unless you reuse the
colour elsewhere. You can just embed the xsl:choose within the
xsl:attribute:
<xsl:template match="event">
<td>
<xsl:attribute name="bgcolor">
<xsl:choose>
<xsl:when test="@type='error'">#990000</xsl:when>
<!-- other colours for other types -->
<xsl:otherwise><!-- default --></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<!-- content of the table cell -->
</td>
</xsl:template>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list