How to concatenate two or more xml files using xslt and maintain the order?

ZyprexaNJ

New Member
If I have this file:input file1.xml:\[code\]<schema> <sequence> <nodeA id="a"> <fruit id="small"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> <fruit id="small"> <apple id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </apple> </fruit> <fruit id="medium"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> </nodeA> <nodeB id="b"> <dog id="large"> <doberman id="x" method="create"> <condition> <color>Black</color> </condition> </doberman> </dog> </nodeB> </sequence></schema>\[/code\]file2.xml:\[code\]<schema> <sequence> <nodeA id="a"> <fruit id="small"> <melon id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </melon> </fruit> </nodeA> <nodeB id="b"> <dog id="small"> <poodle id="x" method="create"> <condition> <color>White</color> </condition> </poodle> </dog> </nodeB> </sequence></schema>\[/code\]After concatenation:output: concate.xml\[code\]<schema> <sequence> <nodeA id="a"> <fruit id="small"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> <fruit id="small"> <apple id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </apple> </fruit> <fruit id="medium"> <orange id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </orange> </fruit> <fruit id="small"> <melon id="x" method="create"> <attributes> <color>Orange</color> <year>2000</year> </attributes> </melon> </fruit> </nodeA> <nodeB id="b"> <dog id="large"> <doberman id="x" method="create"> <condition> <color>Black</color> </condition> </doberman> </dog> <dog id="small"> <poodle id="x" method="create"> <condition> <color>White</color> </condition> </poodle> </dog> </nodeB> </sequence></schema>\[/code\]For the concate it will depend on the file order so the node in file2.xml will be placed under the node of file1.xml (as seen on the example). And I have up to 5 files. How is this achievable using xsl transformation only, i.e the xslt will input 5 files at the same time and outputting 1 file? This is the document structure and the point where we do merge:\[code\]<schema> <sequence> <nodeA id="a"> <fruit id="small"> <orange id="x" method="create"> ... </orange> </fruit> <fruit id="small"> ... </fruit> <fruit id="large"> ... </fruit> <!-- we merge below this --> </nodeA> <nodeB id="b"> <dog id="large"> <doberman id="x" method="create"> ... </doberman> </dog> <dog id="small"> <doberman id="x" method="create"> ... </doberman> </dog> <!-- we merge below this --> </nodeB> <somenode id="any"> ... </somenode> </sequence></schema>\[/code\]Note: If not possible concatenating only two files input will be fine as it can always be repeated for the other files.Also there are various node name in the file (nodeA, nodeB, SomeNode, etc.)so something that can generalize this problem is needed.we can use xsl1.0 or 2.0.Thanks very much.John
 
Back
Top