<xsl:stylesheet extension-element-prefixes="saxon" version="1.0">
   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="//compounds">
     <html>
       <body>
         <h2>
           <xsl:text>Compounds sorted by Chemical Abstracts Registry number</xsl:text>
         </h2>
         <ul>
           <xsl:apply-templates select="compound">
             <xsl:sort select="@CASRN"/>
           </xsl:apply-templates>
         </ul>
         <h2>
           <xsl:text>Compounds sorted by formula</xsl:text>
         </h2>
         <ul>
           <xsl:apply-templates select="compound">
             <xsl:sort select="formula"/>
           </xsl:apply-templates>
         </ul>
       </body>
     </html>
   </xsl:template>

   <xsl:template match="compound">
     <li>
       <xsl:apply-templates select="*|@*"/>
     </li>
   </xsl:template>

   <xsl:template match="@CASRN">
     <xsl:text>CAS RN: </xsl:text>
     <xsl:apply-templates/>
     <br/>
   </xsl:template>

   <xsl:template match="name">
     <xsl:text>Name: </xsl:text>
     <xsl:apply-templates/>
     <br/>
   </xsl:template>

   <xsl:template match="formula">
     <xsl:text>Formula: </xsl:text>
     <xsl:apply-templates/>
     <br/>
   </xsl:template>
 </xsl:stylesheet>