<xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- ##########################################################
   XSL Transformation to create a table of cd information (title,
   artist, genre, track numbers and track listings) from an XML
   document portraying a cd collection.
  ########################################################### -->

  <xsl:template match="/">
  <!-- ##########################################################
   This template matches the "root" element, catalog.  It inserts
   <html> and </html> tags and sets up <head> and <body> 
   sections.  In the <body> it sets up the framework and header
   row of a table in which to display the XML document's data.
  ########################################################### -->
    <html>
      <head>
        <title>My CD Collection</title>
      </head>
      <body>
        <table>
          <tr><th colspan="2">
            <h1>My CD Collection</h1>
          </th></tr>
          <!-- apply the other templates here -->
          <xsl:apply-templates />
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="cd">
  <!-- ##########################################################
   This is the template to apply when a cd element is encountered
   in transforming the XML document.  It sets up a row of the data 
   table previously started (and that will be ended) by the root 
   element's template.
  ########################################################### -->
    <tr><td valign="top">
      <!-- display attribute values for title, artist, genre -->
      <p><b>Title:  </b> <xsl:value-of select="@title" />  <br />
         <b>Artist: </b> <xsl:value-of select="@artist" /> <br />
         <b>Genre:  </b> <xsl:value-of select="@genre" />  <br />
      </p>
    </td><td valign="top">
      <!-- apply the track template here -->
      <p><xsl:apply-templates select="track" /></p>  
    </td></tr>
  </xsl:template>

  <xsl:template match="track">
  <!-- ##########################################################
   This is the template for the track element.
  ########################################################### -->
    <!-- select and display track ID -->
    <xsl:value-of select="@id" />
    <!-- display text in element -->
    <i><xsl:value-of select="." /></i><br />
  </xsl:template>

</xsl:stylesheet>