This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Newbie question:


> So I wish to do something like this, but it does not work...
> 
> <xsl:choose>
> <xsl:when test='@ODD="O"'><table bgcolor="#000066"></td></xsl:when>
> <xsl:when test='@ODD="N"'><table bgcolor="3366CC"></td></xsl:when>
> </xsl:choose>
> 
(a) You can't write half a node to the result tree, and (b) the stylesheet
has to be well-formed XML, which are two different ways of saying that you
can't do this, because the <table> start tag has to be matched by a </table>
end tag (Heaven only knows what the </td> is doing there).

So even though it seems as if:

 <choose>
   <when x><table aa></when>
   <when otherwise><table bb></when>
   ...  
 </choose>
 </table>

wll always generate a matching closing tag, this isn't the way XSLT works,
because it doesn't write tags, it writes nodes.

The simplest solution here is to use a variable:

  <xsl:variable name="color">
  <xsl:choose>
  <xsl:when test='@ODD="O"'>#000066</xsl:when>
  <xsl:when test='@ODD="N"'>#3366CC</xsl:when>
  </xsl:choose>
  </xsl:variable>
  <table bgcolor="{$color}">
     ...
  </table>

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]