XPath - Number Functions Examples

admin's picture
The part of XML document that we will use for the following examples is:
 
..........
<items>
         <item>
                   <productID description="Product_1">CO11</productID>
                   <quantity>5</quantity>
                   <price>1.23</price>
                   <currency>USD</currency>
         </item>
         <item>
                   <productID description="Product_2">CO12</productID>
                   <quantity>7</quantity>
                  <price>2.34</price>
                   <currency>USD</currency>
         </item>
         <item>
                   <productID description="Product_3">CO13</productID>
                   <quantity>9</quantity>
                   <price>3.45</price>
                   <currency>USD</currency>
         </item>
</items>
         <total>53.58</total>
..........
 
1.  sum(Data/instanceData/POdocument/items/item/price)
 
Result: 7.02
 
2.  //item[2]/price * //item[2]/quantity
 
Result: 16.38    
 
3.  round(//items/item[1]/price)
 
Result: 1
 
4.  floor(//items/item[1]/price)
 
Result: 1
 
5.  ceiling(//items/item[1]/price)
 
Result: 2
 
6.  (//items/item[1]/price*//items/item[1]/quantity) + (//items/item[2]/price*//items/item[2]/quantity) + (//items/item[3]/price*//items/item[3]/quantity)
 
Result: 53.58
 
7.  (//items/item[1]/price*//items/item[1]/quantity) + (//items/item[2]/price*//items/item[2]/quantity) + (//items/item[3]/price*//items/item[3]/quantity) = //total
 
Result: true