Q:

Arithmetic operation in xpath on array of elements

I have a requirement to sum amount from every element i have in my response using xpath
,however condition is i am not sure about how many tags I am going to get in my response.
Sum= amount1*value1+ amount2*value2+amount3*value3+....
<root>
  <element>
   <amount>10</amount>
   <value>2</value>
  </element>  
  <element>
   <amount>20</amount>
   <value>2</value>
  </element>  
  <element>
   <amount>30</amount>
   <value>2</value>
  </element> 
</root> 

can some one please help?

A:

You can try below XPath to get summ of all amount nodes:
sum(//element/amount)

Considering updated question:
sum(//element/sum(./amount * ./value))

