Answer 16: Selection

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

   <xsl:template match="/">
    <html>
        <head>
           <title>Element Names</title>
        </head>
        <body>
        <ul>
          <xsl:apply-templates select="descendant::ATOM"/>
         </ul>
         </body>
    </html>
  </xsl:template>

  <!--    red for liquids, blue for gases, black for solids, and green for unknown. -->
  
  <xsl:template match="ATOM">
    <li>
    <xsl:choose>
         <xsl:when test="@STATE='GAS'">
            <span style="color: red"><xsl:value-of select="NAME"/></span>
         </xsl:when>
         <xsl:when test="@STATE='LIQUID'">
            <span style="color: blue"><xsl:value-of select="NAME"/></span>
         </xsl:when>
         <xsl:when test="@STATE='SOLID'">
            <span style="color: black"><xsl:value-of select="NAME"/></span>
         </xsl:when>
         <xsl:otherwise>
            <span style="color: green"><xsl:value-of select="NAME"/></span>
         </xsl:otherwise>
    </xsl:choose></li>
  </xsl:template>
  
</xsl:stylesheet>
View Transformed Document in Browser
Previous | Next | Top | Cafe con Leche

Copyright 2002, 2003 Elliotte Rusty Harold
Elliotte Rusty Harold
Last Modified October 16, 2002