Handling Calculations

We can use arithmetic support in XPath expressions to insert calculated values into the result tree based on values in the source tree. Let's take a hypothetical example in which our order management system is able to export shipment notices as XML documents. These documents include Elements for quantity ordered, quantity shipped, and quantity previously shipped. However, we have a big customer who insists that we send information about backordered quantity, too. Here's the source document.

Source (AddAndSubtract.xml)
<?xml version="1.0" encoding="UTF-8"?>
<AddAndSubtract>
  <QtyOrdered>1000</QtyOrdered>
  <QtyShipped>500</QtyShipped>
  <QtyPreviouslyShipped>0</QtyPreviouslyShipped>
</AddAndSubtract>

Here is the desired result. ...

Get Using XML with Legacy Business Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.