|
next
|
Subject: What is the best way to sum value excluding a large list Author: Kam Chan Date: 21 Aug 2009 06:08 PM
|
Hello,
Given a very large XML doc, I need to sum up the values under a certain node, but excluding a large list (different element names) from the total.
To make a small example, lets say I have the following XML:
<root>
<itemA>
<price>123</price>
</itemA>
<itemB>
<price>234</price>
</itemB>
<itemC>
<price>222</price>
</itemC>
<myItem>
<price>88</price>
</myItem>
<hisHouse>
<price>300000</price>
</hisHouse>
<theZebra>
<price>35.5</price>
</theZebra>
.....
</root>
And I need to add up all the prices except for node names of "itemC", "hisHouse", "theZebra", and a hundred other names.
One solution is:
<xsl:value-of select="sum(/root/*[not(self:itemC)][not(self:hisHouse)]....)" />
That makes a long xpath, and easy to make an error.
Is there a different (better, or may be not better in terms of performance, but better in terms of maintenance or readability) way that we can accomplish this?
Thanks
Kam
|
|
|