xml - How to choose Element with Greatest Value in XSLT? -


i'm forming html document through xslt stylesheet. in document table contain rainfall data, min temperatures , maximum temperatures , solar radiation each day.

the problem have when attempt retrieve highest minimum temperature , highlight cell crashes browser each time load file. have far: weather.xsl

    <?xml version="1.0" encoding="utf-8"?>     <!--     document   : weather.xsl     created on : september 30, 2015, 5:37 pm     author     : rory     description:         purpose of transformation follows.     -->  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">     <xsl:output method="html"/>      <xsl:variable name="year" select="2015"/>     <xsl:variable name="x" select="//measurement[@year=$year]"/>     <xsl:variable name="monthsofyear" select="$x[@day=1]/month"/>     <xsl:variable name="daysofmonth" select="$x[@month=1]/day"/>     <xsl:variable name="highestrainfall" select="$x/rainfall[.!=''][not( . &lt; $x/rainfall)]"/>     <xsl:variable name="highestmintemp" select="//temperature[@type='minimum' , .!=''][not( . &lt; //temperature[@type='minimum'])]" />      <!-- todo customize transformation rules           syntax recommendation http://www.w3.org/tr/xslt      -->     <xsl:template match="weather">         <html>             <head>                 <title>formatted weather outputs (question 6)</title>                  <style>                     .odd{                         background: lightgreen;                     }                     .even{                         background: violet;                     }                     .negative{                         color: red;                     }                     .highest{                         background: gold;                     }                 </style>             </head>             <body>                 <table border="1" style="text-align:center;border-collapse:collapse;">                     <tr>                         <th>date (dd/mm/yyyy)</th>                         <th>min temp (<sup>o</sup>c)</th>                         <th>max temp (<sup>o</sup>c)</th>                         <th>solar radiation (kwh)</th>                         <th>rainfall (mm)</th>                     </tr>                      <!-- display dates 2015 -->                         <xsl:for-each select="measurement[@year='2015']">                             <tr>                                 <xsl:attribute name="class">                                     <xsl:choose>                                         <xsl:when test="(@month mod 2 != 0)">odd</xsl:when>                                         <xsl:otherwise>even</xsl:otherwise>                                     </xsl:choose>                                 </xsl:attribute>                                  <td>                                     <xsl:value-of select="concat(@day, '/', @month, '/', @year)" />                                 </td>                                 <td>                                     <xsl:attribute name="class">                                         <xsl:choose>                                             <xsl:when test="temperature[@type='minimum'] &lt; 0">negative</xsl:when>                                         </xsl:choose>                                     </xsl:attribute>                                     <xsl:variable name="minitemp" select="temperature[@type='minimum']" />                                     <xsl:if test=" $minitemp = $highestmintemp">                                         <xsl:attribute name="style">background-color:gold</xsl:attribute>                                     </xsl:if>                                     <xsl:value-of select="temperature[@type='minimum']" />                                 </td>                                 <td>                                         <xsl:value-of select="temperature[@type='maximum']" />                                                                    </td>                                 <td>                                     <xsl:value-of select="solar"/>                                 </td>                                 <td>                                     <xsl:if test=" rainfall = $highestrainfall">                                         <xsl:attribute name="style">background-color:gold</xsl:attribute>                                     </xsl:if>                                     <xsl:value-of select="rainfall" />                                 </td>                             </tr>                         </xsl:for-each>                 </table>             </body>         </html>     </xsl:template>  </xsl:stylesheet> 

it's crashing @ section looks follows:

<xsl:variable name="minitemp" select="temperature[@type='minimum']" />     <xsl:if test=" $minitemp = $highestmintemp">        <xsl:attribute name="style">background-color:gold</xsl:attribute>     </xsl:if> 

if offer or advice i'd appreciate it.

in own idiocy using code provided me, didn't adjust variable $x. changing line of:

<xsl:variable name="highestmintemp" select="//temperature[@type='minimum' , .!=''][not( . &lt; //temperature[@type='minimum'])]" /> 

to read such fixes it:

<xsl:variable name="highestmintemp" select="$x/temperature[@type='minimum' , .!=''][not( . &lt; $x/temperature[@type='minimum'])]" /> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -