I want to write an xslt to transform one xml file to another. The source XML file is like the following
<orgs>
<organization revenue="10000">
<name>foo</name>
</organization>
<organization parent="foo">
<name>foo2</name>
</organization>
<organization parent="foo2">
<name>foo3</name>
</organization>
</orgs>
The output xml should be as follows
<orgo>
<organization revenue="10000">
<name>foo</name>
<organization>
<name>foo2</name>
<organization><name>foo3</name></organization>
</organization>
</organization>
</orgo>
So far i’ve tried writing the xsl as follows

This transformation:
when applied on the provided XML document:
produces the wanted, correct output:
In case the order of
<organization>elements is random, like in the following XML document:this transformation produces the wanted result: