xsl:value-of select

A

aidy

Hi,

Here is my xsl

<?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>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>
<xsl:choose>
<xsl:when test=".= 'ACTION'">
<td bgcolor="#FFFF00"><xsl:value-of select="."/></td>
</xsl:when>
<xsl:when test=".= 'PASS'">
<td bgcolor="#00ff00"><xsl:value-of select="."/></td>
</xsl:when>
<xsl:when test=".= 'FAIL'">
<td bgcolor="#FF0000"><xsl:value-of select="."/></td>
</xsl:when>
</xsl:choose>
<td><xsl:value-of select="following-sibling::message[1]"/></
td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

ACTION and FAIL have messages associated with them but PASS doesn't

here is the xml

- <testresults>
- <test id="Register">
<description>Register a x account</description>
<teststatus>ACTION</teststatus>
<message>gone to http://x.com/</message>
<teststatus>ACTION</teststatus>
<message>HTML text of Whoops, we are sorry but an error has
occurred... is being verified</message>
<teststatus>PASS</teststatus>
<teststatus>ACTION</teststatus>
<message>HTML text of The generated code you entered was incorrect
is being verified</message>
<teststatus>PASS</teststatus>
<teststatus>ACTION</teststatus>
<message>HTML text of You appear to have an active account with this
email address. is being verified</message>
<teststatus>FAIL</teststatus>
<message>You appear to have an active account with this email
address</message>
<teststatus>ACTION</teststatus>
<message>clicked log out</message>
<teststatus>FAIL</teststatus>
<message>Need to check registered email here, but not having success
with Admin MasterRegCode</message>
<teststatus>ACTION</teststatus>
<message>browser has been closed</message>
</test>

At the moment the xsl create messages for PASS in the HTML. I need
to prevent this.

Aidy
 
M

Martin Honnen

aidy said:
At the moment the xsl create messages for PASS in the HTML. I need
to prevent this.

Well you could use xsl:if test as you have done elsewhere or you could
restructure the whole stylesheet to use xsl:apply-templates and
templates matching the different teststatus values e.g.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="html" indent="yes"/>

<xsl:template match="testresults">
<table border="2">
<thead>
<tr>
<th>TESTID</th>
<th>TEST DESCRIPTION</th>
<th>STATUS</th>
<th>MESSAGE</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="test/teststatus"/>
</tbody>
</table>
</xsl:template>

<xsl:template match="teststatus[. = 'ACTION']">
<tr>
<td>
<xsl:if test="position() = 1">
<xsl:value-of select="../@id"/>
</xsl:if>
</td>
<td><xsl:value-of select="../description"/></td>
<td bgcolor="#FFFF00"><xsl:value-of select="."/></td>
<td><xsl:value-of select="following-sibling::message[1]"/></td>
</tr>
</xsl:template>

<xsl:template match="teststatus[. = 'PASS']">
<tr>
<td>
<xsl:if test="position() = 1">
<xsl:value-of select="../@id"/>
</xsl:if>
</td>
<td><xsl:value-of select="../description"/></td>
<td bgcolor="#00ff00"><xsl:value-of select="."/></td>
<td></td>
</tr>
</xsl:template>

<xsl:template match="teststatus[. = 'FAIL']">
<tr>
<td>
<xsl:if test="position() = 1">
<xsl:value-of select="../@id"/>
</xsl:if>
</td>
<td><xsl:value-of select="../description"/></td>
<td bgcolor="#FF0000"><xsl:value-of select="."/></td>
<td><xsl:value-of select="following-sibling::message[1]"/></td>
</tr>
</xsl:template>

</xsl:stylesheet>
 
M

Martin Honnen

aidy said:
<td><xsl:value-of select="following-sibling::message[1]"/></
td>

If you want to make only a small change then use
<td>
<xsl:value-of select="following-sibling::*[1][self::message]"/>
</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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top