<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : newstylesheet.xsl
    Created on : 17 September 2009, 1:49 PM
    Author     : MJSutherland
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>

    <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    -->
    <xsl:template match="/">
        <html>
            <head>
                <title>table1.xsl</title>
                <style type="text/css">
                   #report .highlight {
                          background-color:#99f;
                          color:yellow;
                    }

                    #report .data {
                          background-color:#ecf5ff;
                          
                    }

                    #report {
                       background-color:black;
                       color:white;
                    }

                    #report table {
                       background-color:white;
                       color:black;
                       margin-left: auto;
                       margin-right: auto;
                    }
                    #report td { text-align:right;
                         padding: 0.5em 0.25em 0.5em 0.25em;
                         font-size:small;
                    }

                    #report tr:first-child {
                    background-color:green;
                    color:yellow;
                    }

                    #report td:first-child {
                       background-color:white;
                    }

                    #report caption {
                        color:yellow;
                    }
                </style>
            </head>
            <body id="report">
                <table border="1" cellspacing="0" >
                    <xsl:apply-templates select="./table/row" />
                </table>
                <p>Highlighted temperatures are the highest value for that month</p>
                
            </body>
        </html>
    </xsl:template>

    <xsl:template match="row">

        <xsl:variable name="maxValue"
          select="(cell[(position()>1) and not(../cell[position()>1]/data > data )])[1]/data" />

        <tr>
            <xsl:for-each select="descendant::data">
                <xsl:choose>
                    
                    <xsl:when test="(. = $maxValue) and (position() > 1)" >
                        <td class="highlight"><xsl:value-of select="." /></td>
                    </xsl:when>
                    
                    <xsl:otherwise>
                        <td class="data"><xsl:value-of select="." /></td>
                    </xsl:otherwise>
                </xsl:choose>
                
            </xsl:for-each>
        
        </tr>
       
       
        
    </xsl:template>
    
 <xsl:template match="row[1]">
     <tr><th colspan="32"><xsl:value-of select="/table/attribute::summary" /></th></tr>
     <xsl:apply-templates />
 </xsl:template>


    <xsl:template match="cell" >
          <td><xsl:value-of select="./data" /></td>
    </xsl:template>


    <xsl:template match="*|text()"/>

</xsl:stylesheet>
