xsl:value-of select

Discussion in 'XML' started by aidy, Feb 20, 2008.

  1. aidy

    aidy Guest

    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
    aidy, Feb 20, 2008
    #1
    1. Advertising

  2. aidy wrote:

    > 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>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 20, 2008
    #2
    1. Advertising

  3. aidy wrote:

    > <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>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 20, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Son KwonNam
    Replies:
    1
    Views:
    890
    Dimitre Novatchev
    Oct 14, 2003
  2. Replies:
    1
    Views:
    3,588
    A. Bolmarcich
    May 27, 2005
  3. Replies:
    1
    Views:
    2,736
    Joris Gillis
    Sep 19, 2005
  4. Kourosh
    Replies:
    6
    Views:
    840
    Peter Flynn
    May 17, 2006
  5. palmiere
    Replies:
    1
    Views:
    386
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page