XSLT - Create duplicate nodes from an XML



I have a multi level XML, I need to duplicate a set of nodes with a new node using XSLT 1.0 Below is a sample xml.



<?xml version="1.0"?>
<Parent>
<ChildL1 Childtype="A">
<ChildL1L1/>
<ChildL1L1/>
<ChildL1L1>
<ChildL1L2>
</ChildL1L1>
</ChildL1>
<ChildL1 Childtype="B">
<ChildL1L1/>
<ChildL1L1/>
<ChildL1L1/>
</ChildL2>
</Parent>


Desired output:



<?xml version="1.0"?>
<Parent>
<ChildL1 Childtype="A">
<ChildL1L1/>
<ChildL1L1/>
<ChildL1L1>
<ChildL1L2>
</ChildL1L1>
</ChildL1>
<ChildL1 Childtype="B">
<ChildL1L1/>
<ChildL1L1/>
<ChildL1L1/>
</ChildL2>
<NewNode>
<ChildL1L1/>
<ChildL1L1/>
<ChildL1L1>
<ChildL1L2>
</ChildL1L1>
</NewNode>
</Parent>


Here the NewNode has the Children nodes of ChildL1 only when Childtype="B".


Thanks in Advance; Let me know if this question is not clear. It is my first time posting this type of question.


No comments:

Post a Comment