Xalan 1.8 on WinXP
What I am really trying to do is produce an HTML table, where I can
dynamically set the foreground colour of the text.
The XML has an element that indicates whether the foreground should be
highlighted or not.
<xsl:variable name="tr_nohi" select="'<tr>'" />
<xsl:variable name="tr_hi" select="'<tr>'" />
<xsl:variable name="tr_nohi_c" select="'</tr>'" />
<xsl:variable name="tr_hi_c" select="'</tr>'" />
<xsl:choose>
<xsl:when test="scores/scores.low_net_score = 1">
<xsl:value-of select="$tr_hi" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$tr_nohi" />
</xsl:otherwise>
</xsl:choose>
So I was thinking of dynamically changing the class attribute on the <tr>
tag to achieve this. I am not sure if that will work yet, but I have run
into some issues producing my output.
This is what I have so far, but the output it generates looks like this:
<tr><td align="center">
I tried something simplier originally:
<xsl:choose>
<xsl:when test="scores/scores.low_net_score = 1">
<tr>
</xsl:when>
<xsl:otherwise>
<tr>
</xsl:otherwise>
</xsl:choose>
But I get errors on this approach:
xalan_transform: Error: ret = -2 - SAXParseException: Expected end of tag
'tr' (http://localhost, line 85, column 25) - <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Which is why I tried to dynamically create the tag.
Does anyone know why the < and > symbols are not expanded?
Does anyone have a better approach to the problem?
TIA,
Dave
Re: Creating a dynamic
Posted by da...@us.ibm.com.
The proposed tactic
<xsl:choose>
<xsl:when test="scores/scores.low_net_score = 1">
<tr class="something">
</xsl:when>
<xsl:otherwise>
<tr class="otherthing">
</xsl:otherwise>
</xsl:choose>
doesn't work because XSLT wants proper nesting of elements. If you
think about the output being a tree structure rather than a text
stream, the reasons may become clearer.
But you can do this:
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="scores/scores.low_net_score=1">something</xsl:when>
<xsl:otherwise>otherthing</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<!-- The rest of the stuff that goes in this tr -->
</tr>
For further guidance, get one of the many books about XSLT.
.................David Marston
|