Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to sort with highest average on top using xslt
    primarykey
    data
    text
    <p>My xml whit xsl i need to create a table where it should show average min and max. this i was able to to do. But I need to sort the table with highest average. How is this done? Sample XML is</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;?xml-stylesheet type="text/xsl" href="simpleReport.xsl"?&gt; &lt;Results&gt; &lt;Sample time="1797" prod="Val1" /&gt; &lt;Sample time="919" prod="Val2" /&gt; &lt;Sample time="2680" prod="Val3" /&gt; &lt;Sample time="545" prod="Val1" /&gt; &lt;Sample time="520" prod="Val2" /&gt; &lt;Sample time="1041" prod="Val3" /&gt; &lt;Sample time="543" prod="Val1" /&gt; &lt;Sample time="491" prod="Val2" /&gt; &lt;Sample time="286" prod="Val3" /&gt; &lt;Sample time="283" prod="Val1" /&gt; &lt;Sample time="782" prod="Val2" /&gt; &lt;Sample time="440" prod="Val2" /&gt; &lt;/Results&gt; </code></pre> <p>This is what i am doing for calculating average</p> <pre><code> &lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output method="html" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" /&gt; &lt;xsl:param name="prodReport" select="'Results'"/&gt; &lt;xsl:template match="Results"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;xsl:value-of select="$prodReport" /&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;xsl:call-template name="ProductList" /&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;xsl:template name="ProductList"&gt; &lt;h2&gt;Pages&lt;/h2&gt; &lt;table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%"&gt; &lt;tr valign="top"&gt; &lt;th&gt;Sample&lt;/th&gt; &lt;th&gt;Count&lt;/th&gt; &lt;th&gt;Average Time&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="/Results/*[not(@prod = preceding::*/@prod)]"&gt; &lt;xsl:variable name="prodName" select="@prod" /&gt; &lt;xsl:variable name="count" select="count(../*[@prod = current()/@prod])" /&gt; &lt;xsl:variable name="totalTime" select="sum(../*[@prod = current()/@prod]/@time)" /&gt; &lt;xsl:variable name="averageTime" select="$totalTime div $count" /&gt; &lt;tr valign="top"&gt; &lt;td&gt; &lt;xsl:value-of select="$prodName" /&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;xsl:value-of select="$count" /&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;xsl:value-of select="$averageTime" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>How do sort based on computed average? the HTML table columns would be ProdName Count AverageTime. where AverageTime would be in descending order.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload