I am trying to sum some XML values in one node based on a value in another node.
The node in Entry that relates to Item is always one RecordNo less than the RecordNo in Item. So the Entry with RecordNo 1 is related to the Item with RecordNo 2.
I want to sum all Item/Cost nodes where IsValid = 1 for the corresponding Entry Node.
I can only use XSLT version 1.0.
I have tried
Sum(../Items/Item[../Entries/Entry[IsValid=1 and RecordNo -1 = ../Entries/Entry/RecordNo]])
My desired output from the example below would be 22.
<Root>
<Items>
<Item>
<Cost>10</Cost>
<RecordNo>2</RecordNo>
<Type>1</Type>
</Item>
<Item>
<Cost>12</Cost>
<RecordNo>5</RecordNo>
<Type>1</Type>
</Item>
<Item>
<Cost>10</Cost>
<RecordNo>9</RecordNo>
<Type>2</Type>
</Item>
</Items>
<Entries>
<Entry>
<IsValid>1</IsValid>
<RecordNo>1</RecordNo>
</Entry>
<Entry>
<IsValid>1</IsValid>
<RecordNo>4</RecordNo>
</Entry>
<Entry>
<IsValid>0</IsValid>
<RecordNo>8</RecordNo>
</Entry>
</Entries>
</Root>