似乎我暂时不能理解Munechian组,所以我需要寻求帮助..
我正在试着把我所有的类型1元素的价格加起来。
我的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>所以我需要的是将所有类型1分组,并将所有类型的价格相加:
这就是我到目前为止在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>我的问题是,我真的不知道把这些行放在哪里,这样它们就不会干扰我其余的代码。
谢谢
发布于 2011-12-23 01:19:46
对于xslt,如果您想对类型1的所有价格求和
<xsl:value-of select="sum(//ad[type = '1']//price)" />https://stackoverflow.com/questions/8583293
复制相似问题