<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:key name="module-by-environment" match="module" use="environment"/>
<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="count(manifest/modules/module) = 0">
      There are no modules available.
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="manifest/modules"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
<xsl:template match="modules">
  <xsl:for-each select="module[count(. | key('module-by-environment', environment)[1]) = 1]">
    <xsl:sort select="environment"/>
    <table class="main-list" cellspacing="0" cellpadding="4" width="100%" border="0">
      <xsl:if test="not(environment = '')">
        <tr>
          <td colspan="2"><b>
            <xsl:choose>
              <xsl:when test="environment='Lte'">
                Autodetect
              </xsl:when>
              <xsl:when test="environment='W9x'">
                Win 98/ME
              </xsl:when>
              <xsl:when test="environment='NT4'">
                Win NT4
              </xsl:when>
              <xsl:when test="environment='W2K'">
                Win 2000/XP/2003
              </xsl:when>
              <xsl:when test="environment='OSX'">
                Mac OSX
              </xsl:when>
            </xsl:choose>
          </b></td>
        </tr>
      </xsl:if>
      <tr class ="main-list-header">
        <td class="main-list-header">Name</td>
        <td class="main-list-header">Size</td>
      </tr>
      <xsl:for-each select="key('module-by-environment', environment)">
        <xsl:sort select="name"/>
        <tr class="main-list-stable">
          <td class="main-list-item" width="80%"><a><xsl:attribute name="href"><xsl:value-of select="fileurl"/></xsl:attribute><xsl:value-of select="name"/></a><br /><xsl:value-of select="description"/></td>
          <td class="main-list-item" width="10%" nowrap="1">            
            <xsl:choose>
              <xsl:when test="filesize &gt; 1048575">
                <xsl:value-of select="format-number(filesize div 1048576,'0.00 MB')"/>
              </xsl:when>
              <xsl:when test="filesize &gt; -1 and filesize &lt; 1048576">
                <xsl:value-of select="format-number(filesize div 1024,'0.00 KB')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
