Subject:flat xml to nested xml comversion trouble Author:david mare Date:29 Oct 2007 08:03 PM
I'm new to XSLT and having trouble with what I think should be pretty simple. I have a fairly flat structured XML file like this:
<root>
<customer>
<name>Fred</name>
<acctnum>111</acctnum>
</customer>
<order>
<ordernum>1</ordernum>
<acctnum>111</acctnum>
<amount>100.00</amount>
</order>
<order>
<ordernum>2</ordernum>
<acctnum>111</acctnum>
<amount>200.00</amount>
</order>
<customer>
<name>Bob</name>
<acctnum>222</acctnum>
</customer>
<order>
<ordernum>1</ordernum>
<acctnum>222</acctnum>
<amount>300.00</amount>
</order>
</root>
As you can see the order nodes are NOT nested within the customer nodes, but are instead related by a common key (customer/acctnum and order/acctnum). The first customer has two orders, the second customer has one order.
I want to transform this so the orders are nested within the customer nodes in a parent/child structure, like this:
The statement select="../order[acctnum=../customer/acctnum]" is not working correctly. It is giving me all the orders in the file for each customer, not just the orders where the acctnum matches. Is there another way I should be doing this?