This question already has an answer here:
- combining xml, xpath or xquery 1 answer
I need to map the following but its difficult because it has different names:
<main>
<order>
<ID>123</ID>
<Name>ABC</Name>
</order>
<order>
<ID>4556</ID>
<Name>AAA</Name>
<ParentID>123</ParentID>
</order>
</main>
The result should be:
<main>
<order>
<ID>123</ID>
<Name>ABC</Name>
<order>
<ID>4556</ID>
<Name>AAA</Name>
<ParentID>123</ParentID>
</order>
</order>
</main>
One approach to copy all
order
nodes with indexn>1
into the first one is the following XSLT:The output looks like this:
Like @michael.hor257k said, conceptually this question is the same as your previous question. I think you're just not understanding the concept. Hopefully the comments in my example will help.
If I understand the question correctly, you want to nest
order
elements inside of their "parent"order
element based onParentID
. Since we're basing it on the ParentID, that's what we'll use for our key...XML Input
XSLT 1.0
Output