<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html">

  <xsl:template match="/top">
    <html><body>
    <hr/>
      <xsl:apply-templates select="mail[@priority!='zero']">
        <xsl:sort select="@priority"/>
        <xsl:sort select="header/from"/>
      </xsl:apply-templates>
    <p/>
    Total number of mails: <xsl:value-of select="count(/top/mail)"/>
    <br/>
    Number of low-priority mails (not displayed): <xsl:value-of select="count(/top/mail[@priority='zero'])"/>
    <hr/>
    </body></html>
  </xsl:template>

  <xsl:template match="mail">
     [<xsl:value-of select="position()"/>] - 
      
     <xsl:value-of select="header/from"/>
     to <xsl:value-of select="header/to"/>:
     <xsl:value-of select="header/subject"/>
     (priority: <xsl:value-of select="@priority"/>)
     <br/>
  </xsl:template>

  </xsl:output>
</xsl:stylesheet>
