trudyhlittle
asked on
xslt copy xml document for each occurance of a repeating node
Hi, I am attempting to copy the contents of an entire XML document once for each occurrence of a repeating node (including it's children) within the same document using XSLT(version 1.0). Each instance of the original document should contain only one of the repeating nodes (RepeatingNode). Basically, I need to change the repeating nodes into a single occurrence and wrap them in a new root node. The elements in the XML can be anything, however the name of the repeating node is always the same. There are thousands of elements in the XML document, so I can't simply just build it. The copy needs to be generic. For example if I have the following XML, I need these results.
<?xml version="1.0" encoding="UTF-8"?>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah ere4.1</Ch ildOfEleme nt1.4.1>
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>1 </ChildOfR epeatingNo de1.1>
<ChildOfRepeatingNode1.2>d ata here</ChildOfRepeatingNode 1.2>
<ChildOfRepeatingNode1.3> and data here</ChildOfRepeatingNode 1.3>
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1 >data here too</ChildOfRepeatingNode1 .4.1>
</ChildOfRepeatingNode1.4>
</RepeatingNode>
<RepeatingNode>
<ChildOfRepeatingNode1.1>2 </ChildOfR epeatingNo de1.1>
<ChildOfRepeatingNode1.2>m ore data</ChildOfRepeatingNode 1.2>
<ChildOfRepeatingNode1.3>m ore data here</ChildOfRepeatingNode 1.3>
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1 >and even more here</ChildOfRepeatingNode 1.4.1>
</ChildOfRepeatingNode1.4>
</RepeatingNode>
<RepeatingNode>
<ChildOfRepeatingNode1.1>3 </ChildOfR epeatingNo de1.1>
<ChildOfRepeatingNode1.2>s ome more</ChildOfRepeatingNode 1.2>
<ChildOfRepeatingNode1.3>s till going</ChildOfRepeatingNod e1.3>
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1 >last time</ChildOfRepeatingNode 1.4.1>
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
I need:
<?xml version="1.0" encoding="UTF-8"?>
<NewTopNode>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah ere4.1</Ch ildOfEleme nt1.4.1>
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>1 </ChildOfR epeatingNo de1.1>
<ChildOfRepeatingNode1.2>d ata here</ChildOfRepeatingNode 1.2>
<ChildOfRepeatingNode1.3> and data here</ChildOfRepeatingNode 1.3>
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1 >data here too</ChildOfRepeatingNode1 .4.1>
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah ere4.1</Ch ildOfEleme nt1.4.1>
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>2 </ChildOfR epeatingNo de1.1>
<ChildOfRepeatingNode1.2>m ore data</ChildOfRepeatingNode 1.2>
<ChildOfRepeatingNode1.3>m ore data here</ChildOfRepeatingNode 1.3>
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1 >and even more here</ChildOfRepeatingNode 1.4.1>
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah ere4.1</Ch ildOfEleme nt1.4.1>
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>3 </ChildOfR epeatingNo de1.1>
<ChildOfRepeatingNode1.2>s ome more</ChildOfRepeatingNode 1.2>
<ChildOfRepeatingNode1.3>s till going</ChildOfRepeatingNod e1.3>
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1 >last time</ChildOfRepeatingNode 1.4.1>
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
</NewTopNode>
Thanks.
<?xml version="1.0" encoding="UTF-8"?>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>1
<ChildOfRepeatingNode1.2>d
<ChildOfRepeatingNode1.3> and data here</ChildOfRepeatingNode
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1
</ChildOfRepeatingNode1.4>
</RepeatingNode>
<RepeatingNode>
<ChildOfRepeatingNode1.1>2
<ChildOfRepeatingNode1.2>m
<ChildOfRepeatingNode1.3>m
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1
</ChildOfRepeatingNode1.4>
</RepeatingNode>
<RepeatingNode>
<ChildOfRepeatingNode1.1>3
<ChildOfRepeatingNode1.2>s
<ChildOfRepeatingNode1.3>s
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
I need:
<?xml version="1.0" encoding="UTF-8"?>
<NewTopNode>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>1
<ChildOfRepeatingNode1.2>d
<ChildOfRepeatingNode1.3> and data here</ChildOfRepeatingNode
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>2
<ChildOfRepeatingNode1.2>m
<ChildOfRepeatingNode1.3>m
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
<XMLTopNode attr1="1234" attr2="hithere" attr3="thanks">
<Element1>
<ChildOfElement1.1>data here</ChildOfElement1.1>
<ChildOfElement1.2>data here2</ChildOfElement1.2>
<ChildOfElement1.3>data here3</ChildOfElement1.3>
<ChildOfElement1.4>
<ChildOfElement1.4.1>datah
</ChildOfElement1.4>
</Element1>
<Element2>data here too</Element2>
<Element3>data here three</Element3>
<RepeatingNode>
<ChildOfRepeatingNode1.1>3
<ChildOfRepeatingNode1.2>s
<ChildOfRepeatingNode1.3>s
<ChildOfRepeatingNode1.4>
<ChildOfRepeatingNode1.4.1
</ChildOfRepeatingNode1.4>
</RepeatingNode>
</XMLTopNode>
</NewTopNode>
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please accept https:#a40599443
It does exactly what the question asks
and at least it shows in a rather generic way how to have access to parent nodes from a child context
and how to let the mechanism of deep copying works
It does exactly what the question asks
and at least it shows in a rather generic way how to have access to parent nodes from a child context
and how to let the mechanism of deep copying works
Not enough information to confirm an answer.