[英]sum by group XSLT “Munechian grouping”
Seems like I can't understand the Munechian grouping for the moment so I need to ask for help.. 似乎我暂时无法理解Munechian分组,因此我需要寻求帮助。
Im trying to sum the price of al my type 1 elements. 我试图对所有我的第1类元素的价格求和。
My XML file looks like this. 我的XML文件如下所示。
<autoads>
<ad>
<type>1</type>
<name>Honda</name>
<model>XL 1000 V</model>
<regyear>2001</regyear>
<price>129900</price>
<addate>20020115</addate>
<volume>1000</volume>
<category></category>
</ad>
<ad>
<type>2</type>
<name>Nissan</name>
<model>Almera 1.4S</model>
<regyear>1997</regyear>
<price>119000</price>
<addate>20020118</addate>
<volume>0</volume>
<category>5 dörrar</category>
</ad>
....
</autoads>
So what I need is to group al the type 1 and sum the price for al of them: 因此,我需要对al类型1进行分组并对其总和求和:
This is what Ive done so far in my XSL file 到目前为止,这是我在XSL文件中所做的
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Fordon</h2>
<table border="1">
<tr bgcolor="#ccc">
<th>Namn</th>
<th>Modell</th>
<th>Beskrivning</th>
<th>Typ</th>
</tr>
<xsl:for-each select="//ad[type != '1']" >
<xsl:sort select="type" order="descending" />
<xsl:sort select="name"/>
<xsl:sort select="model"/>
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="model" /></td>
<td><xsl:value-of select="adtext" /></td>
<td><xsl:value-of select="type" /></td>
</tr>
</xsl:for-each>
</table>
<p>Summan av fordon är <xsl:value-of select="sum(//price)" /> SEK</p>
Antal bilar är <xsl:value-of select="count(/*/*/type[. = 2])"/><br />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The problem that I have is that I really dont know where to put the lines so they wont disturb the rest of my code. 我的问题是我真的不知道将这些行放在哪里,这样它们就不会打扰我的其余代码。
Thanks 谢谢
对于xslt,如果要对类型1的所有价格求和
<xsl:value-of select="sum(//ad[type = '1']//price)" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.