I have an XML inventory of items.
The inventory lists how much if Item with ID 1 I have, how much of Item with ID 2, etc (think each item ID represents 1 product). The list, however, is subdivided, depending on what quantity of items of particular type have a particular mark on them. So, I have let us say:
Item ID Marked? Qty
1 (no) 500
1 ABC 100
1 (no) 50
1 FFFF 333
2 (no) 10000
....
This ir represented in a structure like this:
<Base>
<Item>
<Id>1</Id>
<Qty>500</Qty>
</Item>
<Item>
<Id>1</Id>
<Qty>100</Qty>
<Mark>ABC</Mark>
</Item>
<Item>
<Id>1</Id>
<Qty>50</Qty>
</Item>
<Item>
<Id>1</Id>
<Qty>333</Qty>
<Mark>FFFF</Mark>
</Item>
<Item>
<Id>2</Id>
<Qty>10000</Qty>
</Item>
...
</Base>
Using XQuery transformation I wish to produce, instead of multiple rows per item ID, 1 aggregate row for each item ID, which would list both total sum of quantities per item (both marked and unmarked), and a separate sum for only those quantities of item that are marked (have subtag. I am not concerned about the contents of the individual tags).
In table form what I want would be this:
Item ID Marked Qty Total Qty
1 433 983
2 0 10000
etc.
In actual XML form the transformation should produce something like this:
<Item><Id>1</Id><MarkedQuantity>433</MarkedQuantity><Total>983</Total></Item>
<Item><Id>2</Id><Total>10000</Total></Item>
....
UPD: Edited for clarity.