Link to home
Start Free TrialLog in
Avatar of Lars007
Lars007

asked on

XPath expression listing orders and order totals

Hello,

Attached is a small sample of an Amazon settlement file.

For each <Order> and <Adjustment> node, I need to list AmazonOrderID and the sum of any Amount fields inside, using xpath or similar.

I am using Oxygen XML, but I am open to other tools.

For example //AmazonOrderID gives me:
/SettlementReport[1]/Order[1]/AmazonOrderID[1] - 12342134214
/SettlementReport[1]/Order[2]/AmazonOrderID[1] - 001-2234436-7951404
/SettlementReport[1]/Order[3]/AmazonOrderID[1] - 011-1235465-2323809
/SettlementReport[1]/Adjustment[1]/AmazonOrderID[1] - 201-3232197-1108246
/SettlementReport[1]/Adjustment[2]/AmazonOrderID[1] - 221-6633333-3111456

sum(//Amount) gives me the sum for all orders:
155.21

What I need is something like this:
/SettlementReport[1]/Order[1]/AmazonOrderID (12342134214) / 42.22
/SettlementReport[1]/Order[2]/AmazonOrderID (001-2234436-7951404) / 32.21
/SettlementReport[1]/Order[3]/AmazonOrderID (011-1235465-2323809) / 44.87
/SettlementReport[1]/Adjustment[1]/AmazonOrderID (201-3232197-1108246) / -21.11
/SettlementReport[1]/Adjustment[2]/AmazonOrderID (221-6633333-3111456) / - 31.12

or simply the order id and Amount totals:
12342134214, 42.22
001-2234436-7951404, 32.21
and so forth...

What I am trying to do is to track down why a settlement does not balance with another source, so I need an efficient way to query the settlement XML file.

Suggestions of other efficient tools / methods for this are welcome.

Thanks.
test.xml
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note that I have different totals than you have (likely because I should exclude some of the values... but than just change the XPath in the sum
Avatar of Lars007
Lars007

ASKER

That's a great way to do it, thanks!  

I have not yet bought an XML / XSLT tool, but I quite like the Oxygen tool I am evaluating so far.  But they are not cheap, so I want to make sure I get the right tool for this kind of analysis.  Are there other tools that you recommend that I look into in addition to Oxygen?  It needs to have an XSLT debugger, XPath query tool, etc.
For XPath and XSLT, Oxygen simply is teh best tool
You have Saxon bundled in, you have XPath 1 and 2 evaluation,
you can debug against a number of XSLT processors,
and you get all an XML developer need ... a whole bunch of utility tools,
great workbench it is (and I use a number of different tools for various reasons)
Note that Oxygen also has a splendid user support and forum
Avatar of Lars007

ASKER

A+!