XSLT Style Sheet for the Catalog

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

  <xsl:template match="/">
    <html>
       <xsl:apply-templates select="catalog"/>
    </html>
  </xsl:template>

  <xsl:template match="catalog">
    <head>
       <title><xsl:value-of select="category"/></title>      
    </head>
    <body>
       <!-- Header -->            
       <h1><xsl:value-of select="category"/></h1>
       <ul>
         <xsl:for-each select="composition">
           <xsl:sort select="title"/>
           <li>
             <a href="#{generate-id()}">
               <xsl:value-of select="title"/>
             </a>
           </li>
         </xsl:for-each>
       </ul>
       
       <!-- Body -->            
       <xsl:apply-templates select="composer">
         <xsl:sort select="name/last_name"/>
         <xsl:sort select="name/first_name"/>
         <xsl:sort select="name/middle_name"/>
       </xsl:apply-templates>
       
       <!-- Signature -->      
       <hr/>
       Copyright <xsl:value-of select="copyright"/><br/>
       Last Modified: <xsl:value-of select="last_updated"/><br/>
       <xsl:apply-templates select="maintainer"/>
    </body>
  </xsl:template>
  
  <xsl:template match="composer">
    <h2><xsl:value-of select="name"/></h2>
    <xsl:apply-templates select="../composition[@composer=current()/@id]">
       <xsl:sort select="title"/>      
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="maintainer">
    <a href="{@url}"><xsl:value-of select="name"/></a><br/>
    <a href="mailto:{@email}"><xsl:value-of select="@email"/></a>
  </xsl:template>

  <xsl:template match="composition">
    <h3><xsl:number value="position()"/>.
      <a name="{generate-id()}">
        <xsl:value-of select="title"/>
      </a>
    </h3>

    <ul>
     <xsl:if test="string(date)">
       <li><xsl:value-of select="date"/></li>
     </xsl:if>
     <xsl:if test="string(length)">
       <li><xsl:value-of select="length"/></li>
     </xsl:if>
     <xsl:if test="string(instruments)">
       <li><xsl:value-of select="instruments"/></li>
     </xsl:if>
     <xsl:if test="string(publisher)">
       <li><xsl:value-of select="publisher"/></li>
     </xsl:if>    
    </ul>

    <p><xsl:apply-templates select="description"/></p>    
    
  </xsl:template>

  <!-- pass unrecognized nodes along unchanged -->
  <xsl:template match="*|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>  
  
  
</xsl:stylesheet>

View in Browser
Previous | Next | Top | Cafe con Leche

Copyright 2002-2005 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified March 16, 2005