我需要创建一个表,它应该显示平均最小值和最大值。这是我能够做到的。但我需要以最高的平均值对表格进行排序。这是如何完成的? 示例XML是如何使用xslt排序最高的平均值使用xslt
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="simpleReport.xsl"?>
<Results>
<Sample time="1797" prod="Val1" />
<Sample time="919" prod="Val2" />
<Sample time="2680" prod="Val3" />
<Sample time="545" prod="Val1" />
<Sample time="520" prod="Val2" />
<Sample time="1041" prod="Val3" />
<Sample time="543" prod="Val1" />
<Sample time="491" prod="Val2" />
<Sample time="286" prod="Val3" />
<Sample time="283" prod="Val1" />
<Sample time="782" prod="Val2" />
<Sample time="440" prod="Val2" />
</Results>
这是我在做什么的
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
<xsl:param name="prodReport" select="'Results'"/>
<xsl:template match="Results">
<html>
<head>
<title><xsl:value-of select="$prodReport" /></title>
</head>
<body>
<xsl:call-template name="ProductList" />
</body>
</html>
</xsl:template>
<xsl:template name="ProductList">
<h2>Pages</h2>
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th>Sample</th>
<th>Count</th>
<th>Average Time</th>
</tr>
<xsl:for-each select="/Results/*[not(@prod = preceding::*/@prod)]">
<xsl:variable name="prodName" select="@prod" />
<xsl:variable name="count" select="count(../*[@prod = current()/@prod])" />
<xsl:variable name="totalTime" select="sum(../*[@prod = current()/@prod]/@time)" />
<xsl:variable name="averageTime" select="$totalTime div $count" />
<tr valign="top">
<td>
<xsl:value-of select="$prodName" />
</td>
<td align="center">
<xsl:value-of select="$count" />
</td>
<td align="right">
<xsl:value-of select="$averageTime" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
如何排序基于计算的平均值计算平均? HTML表格列将是ProdName Count AverageTime。平均时间将按降序排列。
谢谢
见http://stackoverflow.com/questions/758527/xsl-how-can-i-group-and-sort-based-on- sum –
请包含更多样式表,以及您期望的输出XML(HTML)。 –
我已更新我的样式表。我经历了链接,但不明白“sum(key('kResultByOwner',@Owner)/ @ * [name()= $ pSortBy]) – kumar