| Subject: RE: [xsl] Setting table row color with xsl:choose and  xsl:variable From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Mon, 31 Oct 2005 17:20:43 -0000 | 
You need to write
<xsl:variable name="rowClass">
  <xsl:choose>
    <xsl:when test="condition1">value1</xsl:when>
    <xsl:when test="condition2">value2</xsl:when>
  </xsl:choose>
</xsl:variable>
Alternatively, write:
  <tr>
    <xsl:attribute name="rowClass">
      <xsl:choose>
        <xsl:when test="condition1">value1</xsl:when>
        <xsl:when test="condition2">value2</xsl:when>
      </xsl:choose>
    </xsl:attribute>
    <td>
      ....
or in 2.0
  <tr rowClass="{if (condition1) then value1
                 else if (condition2) then value2
                 else default-value}">
Michael Kay
http://www.saxonica.com/ 
> -----Original Message-----
> From: aevarga@xxxxxx [mailto:aevarga@xxxxxx] 
> Sent: 31 October 2005 11:02
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx; aevarga@xxxxxx
> Subject: [xsl] Setting table row color with xsl:choose and 
> xsl:variable
> 
> I would like to set the color of a table row based on the 
> value in one of the data fields.  The long way, which works, 
> is to repeat the entire <tr><td> pattern for each value.  
> Isn't it possible using some variation of the following code 
> to just read the field's value, assign a CSS class to the row 
> and continue with template matching for the <td>'s?
> 
> 
> 
> <xsl:template match="Event">         
> 
> <xsl:choose>
> 
>   <xsl:when test="Required = 'yes'">
> 
>     <xsl:variable name="rowClass">calendarltred</xsl:variable>
> 
>   </xsl:when>
> 
>   <xsl:when test="Special = 'meeting'">
> 
>     <xsl:variable name="rowClass">calendaryellow</xsl:variable>
> 
>   </xsl:when>
> 
>   <xsl:when test="Special = 'candysale'">
> 
>     <xsl:variable name="rowClass">calendarltblue</xsl:variable>
> 
>   </xsl:when>
> 
>   <xsl:otherwise>
> 
>     <xsl:variable name="rowClass">default</xsl:variable>
> 
>   </xsl:otherwise>
> 
> </xsl:choose>
> 
>     <tr class="{$rowClass}">
> 
>       <td>
> 
>         <xsl:apply-templates select="DayOfWeek" />
> 
>         <xsl:apply-templates select="MonthName" />
> 
>         <xsl:apply-templates select="DayNum" />
> 
>       </td>
> 
> ...
> 
> 
> 
> Thanks, Alan
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] Setting table row color w, David Carlisle | Thread | [xsl] Re: XSL:sort dates as numbers, Ninad Tambe | 
| RE: [xsl] Re: XSL:sort dates as num, Michael Kay | Date | Re: [xsl] Setting table row color w, David Carlisle | 
| Month |