The Open Source Swiss Army Knife

/xml/
/xml/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /xml 
Permalink: fchuz.htm
Title: add
article options : please login   |  print view

to insert a conditional choose test against the content of the file, simply add the xsl:choose, xsl:when and xsl:otherwise elements to your xsl document like this:

<xsl:choose>
   <xsl:when test=".[artist='bob dylan']">
      ... some code ...
   </xsl:when>
   <xsl:otherwise>
      ... some code ....
   </xsl:otherwise>
</xsl:choose>

now take a look at your slightly adjusted xsl stylesheet:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/tr/wd-xsl">
<xsl:template match="/">
  <html>
  <body>
    <table border="2" bgcolor="yellow">
      <tr>
        <th>title</th>
        <th>artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
        <tr>
        <td><xsl:value-of select="title"/></td>
        <xsl:choose>
          <xsl:when test=".[artist='bob dylan']">
            <td bgcolor="#ff0000">
             <xsl:value-of select="artist"/>
            </td>
          </xsl:when>
          <xsl:otherwise>
            <td><xsl:value-of select="artist"/></td>
          </xsl:otherwise>
        </xsl:choose>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
try it out

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top