topical media & game development

talk show tell print

basic-ajax-08-runners.xsl / xsl



  <?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" 
      indent="yes" 
      version="4.0" />
     
    <xsl:template match="/">
      <table border="1">
        <thead>
          <tr>
            <td>Position</td>
            <td>Name</td>
            <td>Time</td>
          </tr>
        </thead>
        <xsl:for-each select="//runner">
          <xsl:sort select="totalseconds"/>
          <tr>
            <td>
              <xsl:value-of select="position()"/>
            </td>
            <td>
              <xsl:value-of select="name"/>
            </td>
            <td>
              <xsl:value-of select="floor(totalseconds div 60)"/>.
              <xsl:choose>
                <xsl:when test ="(totalseconds mod 60) &gt; 9">
                  <xsl:value-of select="(totalseconds mod 60)"/>
                </xsl:when>
                <xsl:otherwise>
                    0<xsl:value-of select="(totalseconds mod 60)"/>
                </xsl:otherwise>
              </xsl:choose>
            </td>
          </tr>
        </xsl:for-each>
        <tr>
          <td>Average Time:</td>
          <td>
          </td>
          <td>
            <xsl:variable name="avgtime" select="sum(//totalseconds) div count(//runner)"/>
            <xsl:value-of select="floor(avgtime div 60)"/>.
              <xsl:choose>
                <xsl:when test ="(avgtime mod 60) &gt; 9">
                  <xsl:value-of select="(avgtime mod 60)"/>
                </xsl:when>
                <xsl:otherwise>
                    0<xsl:value-of select="(avgtime mod 60)"/>
                </xsl:otherwise>
              </xsl:choose>
          </td>
        </tr>
      </table>
    </xsl:template>
  
  </xsl:stylesheet>
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.