Reputation: 58
I am attempting to find the sum of the Amount tag where a preceding-sibling condition is met. The data comes from a Sql Data Base and the order of the XML cannot be changed.
<NewDataSet>
<Table>
<Store_NUM>
1101
</Store_NUM>
<Amount>
10,000
</Amount>
</Table>
<Table>
<Store_NUM>
1101
</Store_NUM>
<Amount>
15,000
</Amount>
</Table>
<Table>
<Store_NUM>
1101
</Store_NUM>
<Amount>
12,000
</Amount>
</Table>
<Table>
<Store_NUM>
1103
</Store_NUM>
<Amount>
10,000
</Amount>
</Table>
<Table>
<Store_NUM>
1103
</Store_NUM>
<Amount>
10,000
</Amount>
</Table>
<Table1>
<Run_Date>
2013-12-06
</Run_Date>
<Run_Time>
08:20:56.254
</Run_Time>
</Table1>
</NewDataSet>
I want to find the sum of where Store_NUM equals 1101. Is this achievable?
Upvotes: 0
Views: 177
Reputation: 167696
Use sum(//Table[normalize-space(Store_NUM) = '1101']/Amount)
. But your numbers using a comma are not in the right format, it should be floating point format.
If you have a variable or param $foo
use sum(//Table[normalize-space(Store_NUM) = $foo]/Amount)
.
Upvotes: 1