[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Trying to display Summed Average of Grouped Data
Been Struggling for a day or 2 now :(
I know your all gonna cringe at this code because im much of an XSLT'er and tend to work via trial and error.... In Brief im trying to display the Averages of each Column for each individual Days results so far all the methods ive tried have either led to a "0" or the summing of the Entire collection rather than per day...i tried using variables but found it impossible to manipulate...i fear my xpath knowledge is letting me down ... any comments hints helpfull tid bits would be GREATLY appreciated Ty in Advanced The XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:key name="rows" match="Log" use="@Date"/> <xsl:variable name="CPUAVG" select="0"/> <xsl:variable name="CASEAVG" select="0"/> <xsl:variable name="DISKAVG" select="0"/> <xsl:variable name="CPUFANAVG" select="0"/> <xsl:variable name="CASEFANAVG" select="0"/> <xsl:variable name="TEMP" select="0"/> <xsl:template match="MBM_INTERVAL"> <html> <head> <body> <h2 style="color: #6633CC; margin-left: 20px">My Stats</h2> <table width="775" height="311" border="1"> <tr> <td width="500" rowspan="3"> <xsl:apply-templates select="Log[generate-id(.) = generate-id(key('rows', @Date)[1])]"/> </td> <td width="228"/> <td width="202"/> </tr> <tr> <td/> <td/> </tr> <tr> <td/> <td/> </tr> </table> </body> </head> </html> </xsl:template> <xsl:template match="Log"> <xsl:variable name="Count" select="count(key('rows',@Date))"/> <table> <tr> <td bgcolor="#99CCCC">Date:</td> <td bgcolor="#cccc99"> <xsl:value-of select="@Date"/> </td> <td bgcolor="#99CCCC">Records:</td> <td bgcolor="#cccc99"> <xsl:value-of select="$Count"/> </td> </tr> <td bgcolor="#99CCCC">Averages:</td> <xsl:variable name="CPUAVG" select="$CPUAVG+@T_CPU div $Count"/> <xsl:variable name="CASEAVG" select="$CASEAVG+@T_Case div $Count"/> <xsl:variable name="DISKAVG" select="$DISKAVG+@T_Master_Disk div $Count"/> <xsl:variable name="CPUFANAVG" select="$CPUFANAVG+@ F_Fan_1 div $Count"/> <xsl:variable name="CASEFANAVG" select="$CASEFANAVG+@ F_Fan_2 div $Count"/> <td bgcolor="#cccc99"> <xsl:value-of select="round($CPUAVG)"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="round($CASEAVG)"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="round($DISKAVG)"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="round($CPUFANAVG)"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="round($CASEFANAVG)"/> </td> <tr> <td bgcolor="#99CCCC">Time</td> <td bgcolor="#99CCCC">CPU Temp</td> <td bgcolor="#99CCCC">Case Temp</td> <td bgcolor="#99CCCC">Disk Temp</td> <td bgcolor="#99CCCC">CPU Fan</td> <td bgcolor="#99CCCC">Case Fan</td> </tr> <xsl:for-each select="key('rows', @Date)"> <tr> <td bgcolor="#cccc99"> <xsl:value-of select="@Time"/> </td> <td bgcolor="cccc99"> <xsl:value-of select="@T_CPU"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="@T_Case"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="@T_Master_Disk"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="@ F_Fan_1"/> </td> <td bgcolor="#cccc99"> <xsl:value-of select="@ F_Fan_2"/> </td> </tr> </xsl:for-each> <br/> </table> </xsl:template> </xsl:stylesheet> The XML: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="stats.xsl"?> <MBM_INTERVAL> <Log Date="24/08/2004" Time="18:53:31" CPU="1808" T_Case="40" T_CPU="1" T_Master_Disk="37" F_Fan_1="4115" F_Fan_2="1527"/> <Log Date="24/08/2004" Time="18:52:31" CPU="1808" T_Case="40" T_CPU="3" T_Master_Disk="37" F_Fan_1="4115" F_Fan_2="1527"/> <Log Date="24/08/2004" Time="18:52:31" CPU="1808" T_Case="40" T_CPU="3" T_Master_Disk="37" F_Fan_1="4115" F_Fan_2="1527"/> <Log Date="25/08/2004" Time="18:51:31" CPU="1808" T_Case="40" T_CPU="1" T_Master_Disk="37" F_Fan_1="4115" F_Fan_2="1520"/> <Log Date="26/08/2004" Time="18:50:31" CPU="1808" T_Case="40" T_CPU="9" T_Master_Disk="37" F_Fan_1="4115" F_Fan_2="1527"/> <Log Date="26/08/2004" Time="18:49:31" CPU="1808" T_Case="40" T_CPU="55" T_Master_Disk="37" F_Fan_1="4115" F_Fan_2="1527"/> </MBM_INTERVAL> -{Dom}- _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|