Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Parent/Child nodes from flat XML structure

Status
Not open for further replies.

aswolff

Programmer
Jul 31, 2006
100
US
Hello,

I have the following structure in an XML file that needs to be tranformed to the second structure..if somebody could provide a hint on how this could be accomplished. Thanks.

<ROOT>
<PARENT>
<INVOICE>A</INVOICE>
<VENDOR>X</VENDOR>
<SEQUENCE>1</SEQUENCE>
<AMOUNT>2</AMOUNT>
</PARENT>
<PARENT>
<INVOICE>A</INVOICE>
<VENDOR>X</VENDOR>
<SEQUENCE>2</SEQUENCE>
<AMOUNT>3</AMOUNT
</PARENT>
<PARENT>
<INVOICE>B</INVOICE>
<SEQUENCE>1</SEQUENCE>
<VENDOR>Y</VENDOR>
<AMOUNT>4</AMOUNT>
</PARENT>
</ROOT>

And Needs to be transformed via XSLT To:

<ROOT>
<PARENT>
<INVOICE>A</INVOICE>
<VENDOR>X</VENDOR>
<CHILD>
<SEQUENCE>1</SEQUENCE>
<AMOUNT>2</AMOUNT>
</CHILD>
<CHILD>
<SEQUENCE>2</SEQUENCE>
<AMOUNT>3</AMOUNT>
</CHILD>
</PARENT>
<PARENT>
<INVOICE>B</INVOICE>
<VENDOR>Y</SEQUENCE>
<CHILD>
<SEQUENCE>1</SEQUENCE>
<AMOUNT>4</AMOUNT>
</CHILD>
</PARENT>
</ROOT>

So for each unique <invoice> <vendor> combination...I want to create child nodes that contain the <sequence> and <amount> elements.


 
This is grouping. Presuming that you are using an XSLT 1.0 processor (XSLT is the language used to transform one XML document into another document), you will need to use the Muench method of grouping, described by me near the end of this thread: thread426-1210886.

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top