In XSLT 1.0/XPATH 1.0, without using any external libraries/node set extensions, I need to be able to sum the cost values of items (for the person's share) of a specific item's type. For example, in the sample XML below, how would I sum the costs for type 'Box' and person 'Andrew'? The expected output for this is '1500' (0.5*1000 + 1*1000).
`<items>
<item>
<type>Box</type>
<cost>1000.00</cost>
<share>
<person>
<name>Jim</name>
<percent>50</percent>
</person>
<person>
<name>Andrew</name>
<percent>50</percent>
</person>
</share>
</item>
<item>
<type>Box</type>
<cost>1000.00</cost>
<share>
<person>
<name>Andrew</name>
<percent>100</percent>
</person>
</share>
</item>
<item>
<type>Car</type>
<cost>2000.00</cost>
<share>
<person>
<name>Andrew</name>
<percent>100</percent>
</person>
</share>
</item>
<item>
<type>Box</type>
<cost>2000.00</cost>
<share>
<person>
<name>Jim</name>
<percent>100</percent>
</person>
</share>
</item>
</items>`
In XSLT, I could have a for-each loop:
`<xsl:for-each select="/items/item[type='Box' and share/person/name='Andrew']">
<xsl:value-of select="share/person[name='Andrew']/percent div 100) * cost"/>
</xsl:for-each>`
but this won't sum the totals. I don't think sum() can be used since it needs to multiple the person's share by the amount for each specific item. I don't know how to store this in a variable with the for-each loop inside due to XSLT restrictions. I think recursion might be able to be used but I am not sure how.