I have an XML file which looks like the following:
<a>
......
<b>
<c>
<c1>some text</c1>
</c>
<d>
<d1>some more text</d1>
<d1>even more text</d1>
</d>
<e>
<e1>some more text</e1>
<e1>even more text</e1>
</e>
</b>
</a>
And I want to wrap elements <d> and <e> into a <wrapper> element, so I can have something like the following:
<a>
......
<b>
<c>
<c1>some text</c1>
</c>
<wrapper>
<d>
<d1>some more text</d1>
<d1>even more text</d1>
</d>
<e>
<e1>some more text</e1>
<e1>even more text</e1>
<e2>even more</e2>
</e>
</wrapper>
</b>
......
</a>
One of the problems that I’m facing (apart from the fact that I’m new to XSLT) is that both <d> and <e> are optional.
How can I do this?
This transformation:
when applied on the provided XML document:
produces the wanted result:
Note: Overriden identity rule + modes.