Product: Mapping Manager
Article Link:
xPath is capable of performing Mathematical Operations across multiple nodes in order to produce a result.
Example XML
<Invoice>
<Header>
<InvoiceNumber>INV-10001</InvoiceNumber>
<Date>2024-10-18</Date>
<CustomerID>12345</CustomerID>
</Header>
<LineItems>
<Item>
<Description>Widget A</Description>
<Quantity>10</Quantity>
<UnitPrice>15.00</UnitPrice>
</Item>
<Item>
<Description>Widget B</Description>
<Quantity>5</Quantity>
<UnitPrice>20.00</UnitPrice>
</Item>
<Item>
<Description>Widget C</Description>
<Quantity>7</Quantity>
<UnitPrice>25.00</UnitPrice>
</Item>
</LineItems>
<Summary>
<Subtotal>425.00</Subtotal>
<TaxAmount>42.50</TaxAmount>
<DiscountAmount>100</DiscountAmount>
</Summary>
</Invoice>
Mathematical Operations
| Operator |
Add | + |
Subtract | - |
Multiply | * |
Divide | div |
Add
Summary/(Subtotal + TaxAmount)
467.5
<Summary>
<Subtotal>425.00</Subtotal>
<TaxAmount>42.50</TaxAmount>
</Summary>
In the Summary group there is a Subtotal and a TaxAmount - we can combine these together by adding them together
Subtract
Summary/(Subtotal - DiscountAmount)
325.00
<Summary>
<Subtotal>425.00</Subtotal>
<DiscountAmount>100</DiscountAmount>
</Summary>
We can subtract the Discount from the Subtotal to give us a Total Amount fairly easily
Multiply
//Item[3]/(Quantity * UnitPrice)
175
The third item in the XML has a Quantity of 10 and a UnitPrice of 15.00
<Item>
<Quantity>10</Quantity>
<UnitPrice>15.00</UnitPrice>
</Item>
By multiplying those two together - you end up with a 175 as the result.
Divide
Since our pathing is done through the typical division sign of a forward slash - you can divide by typing out 'div' in between your desired operand.
Summary/(TaxAmount div Subtotal)
0.10
<Summary>
<Subtotal>425.00</Subtotal>
<TaxAmount>42.50</TaxAmount>
</Summary>
The Summary group is missing the Tax Rate, we can easily divide the TaxAmount by the Subtotal in order to calculate that rate. 42.50 / 425 is equal to .10, (10%)
rev 10/18/2024