<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xmlverbatimwrapper.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
  <xsl:template match="/basket">
    <html>
      <head>
        <title>Computer-on-a-Platter, now serving: 
        <xsl:value-of select="sysInfo/computerName" /></title>
        <style>th {font-family: Garamond;} td { font-family: Arial,
        Verdana, sans-serif; } td.programs { font-size:
        12px;}</style>
      </head>
      <body>
        <center>
          <table width="80%" class="c1" style="border: 1px solid black;">
            <tr bgcolor="#ffddd0">
              <th colspan="2">
                <xsl:value-of select="sysInfo/computerName" />
              </th>
            </tr>
            <tr>
              <td colspan="2">...by 
              <xsl:value-of select="sysInfo/manufacturer" />, model
              
              <xsl:value-of select="sysInfo/model" /></td>
            </tr>
            <tr>
              <th>OS</th>
              <td>
              <xsl:value-of select="sysInfo/OSname" />(
              <xsl:value-of select="sysInfo/OSversion" />)</td>
            </tr>
            <tr>
              <th>IP</th>
              <td>
                <xsl:value-of select="sysInfo/IPAddress" />
              </td>
            </tr>
            <tr>
              <th>Memory</th>
              <td>
                <xsl:value-of select="sysInfo/totalMemory" />
              </td>
            </tr>
            <tr>
              <th>Hard Drive</th>
              <td>
              <xsl:value-of select="sysInfo/HDmodel" />, 
              <xsl:value-of select="sysInfo/HDsize" /></td>
            </tr>
            <tr>
              <th>Partitions</th>
              <td>
                <table width="100%">
                  <tr bgcolor="#ffcc80">
                    <th width="10%">Drive</th>
                    <th width="15%">Type</th>
                    <th width="75%">Free Space</th>
                  </tr>
                  <xsl:for-each select="sysInfo/partitions/diskPartition">

                    <tr>
                      <td>
                        <xsl:value-of select="name" />
                      </td>
                      <td>
                        <xsl:value-of select="fileSystem" />
                      </td>
                      <td>
                        <table width="100%">
                          <tr>
                            <td width="70%">
                              <table width="100%">
                                <tr>
                                  <td>
                                    <xsl:attribute name="bgcolor">
                                      <xsl:call-template name="getBackgroundColor">
                                        <xsl:with-param name="free">
                                          <xsl:call-template name="getFreeSpace" />
                                        </xsl:with-param>
                                      </xsl:call-template>
                                    </xsl:attribute>
                                    <xsl:attribute name="width">
                                    <xsl:call-template name="getFreeSpace" />%</xsl:attribute>
                                    <center>
                                      <xsl:choose>
                                      	<xsl:when test="round(substring-before(freeSpace, ' ') * 100 div substring-before(size, ' ')) > 12">
                                      			<b><xsl:call-template name="getFreeSpace" />%</b>
                                      	</xsl:when>
                                      	<xsl:otherwise><font><xsl:attribute name="color"><xsl:call-template name="getBackgroundColor"/></xsl:attribute>.</font>
                                      	</xsl:otherwise>
                                      </xsl:choose>
                                      
                                    </center>
                                  </td>
                                  <td>
                                  	<xsl:attribute name="width">
                                  		<xsl:call-template name="getUsedSpace"/>%
                                  	</xsl:attribute>
                                      <xsl:choose>
                                      	<xsl:when test="round(substring-before(freeSpace, ' ') * 100 div substring-before(size, ' ')) > 10">
                                      			<font color="white">.</font>
                                      	</xsl:when>
                                      	<xsl:otherwise>
                                      	<b><xsl:call-template name="getFreeSpace" />%</b>
                                      	</xsl:otherwise>
                                      </xsl:choose>
                                  </td>
                                </tr>
                              </table>
                            </td>
                            <td width="30%">
                            <xsl:value-of select="freeSpace" />/ 
                            <xsl:value-of select="size" /></td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </xsl:for-each>
                </table>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <table width="100%">
                  <tr bgcolor="#c0c0c0">
                    <th colspan="3">All Known Programs</th>
                  </tr>
                  <xsl:variable name="progOffset"
                  select="count(//string) div 3" />
                  <xsl:call-template name="listPrograms">
                    <xsl:with-param name="cnt">1</xsl:with-param>
                    <xsl:with-param name="offset"
                    select="round($progOffset)" />
                  </xsl:call-template>
                </table>
              </td>
            </tr>
            <!-- <xsl:for-each select="programs/list/string">
<tr><td class="programs" colspan="2"><xsl:value-of select="."/></td></tr>
</xsl:for-each> -->
          </table>
        </center>
      </body>
    </html>
  </xsl:template>
  <xsl:template name="listPrograms">
    <xsl:param name="cnt" />
    <xsl:param name="offset" />
    <tr>
      <td class="programs">
        <xsl:value-of select='programs/list/string[$cnt]' />
      </td>
      <td class="programs">
        <xsl:value-of select='programs/list/string[$cnt + $offset]' />
      </td>
      <td class="programs">
        <xsl:value-of select='programs/list/string[$cnt + $offset * 2]' />
      </td>
    </tr>
      <xsl:if test="($cnt + 1) &lt; $offset">
        <xsl:call-template name="listPrograms">
          <xsl:with-param name="cnt" select="$cnt + 1" />
          <xsl:with-param name="offset" select="$offset" />
        </xsl:call-template>
      </xsl:if>

  </xsl:template>
  <xsl:template name="getBackgroundColor">
    <xsl:param name="free" />
    <xsl:choose>
      <xsl:when test="$free &gt; 80">green</xsl:when>
      <xsl:when test="$free &gt; 50">orange</xsl:when>
      <xsl:otherwise>red</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="getFreeSpace">
    <xsl:value-of select="round(substring-before(freeSpace, ' ') * 100 div substring-before(size, ' '))" />
  </xsl:template>
  <xsl:template name="getUsedSpace">
    <xsl:value-of select="100 - (round(substring-before(freeSpace, ' ') * 100 div substring-before(size, ' ')))" />
  </xsl:template>
</xsl:stylesheet>
