Použití podmínek

Příklad 5. katalog-podminky.xsl

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

<xsl:output method="html" encoding="utf-8"/>
  
<xsl:template match="/">
  <html>
    <head>
      <title><xsl:value-of select="/katalog/nazev"/></title>
      <style type="text/css">
        body   { color: black; background-color: white; }
        table  { border: solid 2px black; border-collapse: collapse; }
        th a   { text-decoration: none; color: black; }
        th     { background-color: #FF8000; }
        th, td { border: solid 1px black; }
        .even  { background-color: #FFFF80; }
      </style> 
    </head>
    <body>
      <h1>
        <xsl:value-of select="/katalog/nazev"/>
      </h1>
  
      <table width="100%">
        <tr>
          <th>#</th>
          <th>Název</th>
          <th>Kategorie</th>
          <th>Cena</th>
        </tr>  
        <xsl:for-each select="/katalog/polozka">
          <tr>
            <!-- Podmíněné obarvení sudých/lichých řádek -->
            <xsl:if test="position() mod 2 = 0">
              <xsl:attribute name="class">even</xsl:attribute>
            </xsl:if>
            <td align="center"><xsl:value-of select="position()"/>.</td>
            <td align="center">
              <xsl:value-of select="nazev"/><br/>
              <small>
                <b>Doporučené příslušenství: </b>
                <!-- Doplnění popisu na základě kategorie -->
                <xsl:choose>
                  <xsl:when test="kategorie = 'MiniDisc'">
                    prázdná MD média
                  </xsl:when>
                  <xsl:when test="kategorie = 'Receiver'">
                    anténa a nezapomeňte 
                    na <a href="http://www.rozhlas.cz/poplatek">rozhlasový
                    poplatek</a>
                  </xsl:when>
                  <xsl:otherwise>-</xsl:otherwise>
                </xsl:choose>
              </small>
            </td>
            <td align="center"><xsl:value-of select="kategorie"/></td>
            <td align="right"><xsl:value-of select="cena"/></td>
          </tr>
        </xsl:for-each>
      </table>
    </body>
  </html>    
</xsl:template>

</xsl:stylesheet>