//flex table opened by JP

Click to See Complete Forum and Search --> : xsl:when


gnom
06-27-2005, 04:19 PM
Here is a fragment of xml file:
<?xml version="1.0" <?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE logs [
<!ELEMENT logs (log*)>
<!ELEMENT log (query)>
<!ATTLIST log
type CDATA #REQUIRED
date CDATA #REQUIRED
time CDATA #REQUIRED>
<!ELEMENT query (#PCDATA)>
]>
and below is xsl file:
<xsl:for-each select="logs/log">
<xsl:sort select="@date" order="descending"/>
<table align="center" border="0">
<xsl:choose>
<xsl:when test="type=add">
<font color="#FF0000">
.......
</font>
</xsl:when>
<xsl:when test="type = modify">
<font color="#FFCC00">
...........
</font>
</xsl:when>
<xsl:when test="type = delete">
<font color="#99CC00">
.........
</font>
</xsl:when>
<xsl:otherwise>
<font>
.........
</font>
</xsl:otherwise>
</xsl:choose>
</table>
<br />
</xsl:for-each>

Now my problem is that for example xsl:when test="type = delete" doesn't work. The color is not changed. What is the proper way of comparing value of type tag with a string?

ScaryBinary
06-28-2005, 01:14 AM
I couldn't find any "clean" examples of using strings in XSL (I'm not too familiar with it yet...), but I would try something like:<xsl:choose>
<xsl:when test="type='add'">
...in other words, surround your value in single quotes.

The link below goes to an example....they use some weird "match" keyword that I don't see in your sample....I don't know if it's necessary or not, but you can see they enclosed the value string in quotes.

XML/XSL Example (http://www.xmlfiles.com/xsl/xsl_choose.asp)

gnom
06-28-2005, 06:06 AM
it should be:
<xsl:when test="@type = 'add'">
thanks for help