if test to colour

A

aidy

Hi

I have some xml that is similar to this

<testresults>
<test id="test_1">
<description>demo test method 1</description>
<teststatus>PASS</teststatus>
</test>
<test id="test_2">
<description>demo test method 2</description>
<teststatus>FAIL!</teststatus>
<failmessage>the remember me checkbox should be set and is not</
failmessage>
</test>
</testresults>

this is the xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="testresults">
<table border="2">
<tr>
<td><b>TESTID</b></td>
<td><b>TEST DESCRIPTION</b></td>
<td><b>STATUS</b></td>
<td><b>FAILURE MESSAGE</b></td>
</tr>
<xsl:apply-templates />
</table>
</xsl:template>
<xsl:template match="test">
<xsl:for-each select="teststatus">
<tr>
<td>
<xsl:if test="position()=1">
<xsl:value-of select="../@id"/>
</xsl:if>
</td>
<td><xsl:value-of select="../description"/></td>
said:
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


the one thing I am stuck on is if I have a test status of 'PASS' I
would like to colour the cell limegreen and if a 'FAIL' red.

cheers

aidy
 
M

Martin Honnen

aidy said:
the one thing I am stuck on is if I have a test status of 'PASS' I
would like to colour the cell limegreen and if a 'FAIL' red.

Then add a bgcolor attribute e.g. instead of
<td><xsl:value-of select="."/></td>
use
<td>
<xsl:attribute name="bgcolor">
<xsl:choose>
<xsl:when test=". = 'PASS'">limegreen</xsl:when>
<xsl:eek:therwise>red</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
</td>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top