I have an almost flat xml with several entries having info related to headings which are to be displayed before the entries' metadata. These headings can be in two levels and second level is optional. Kindly suggest a way to achieve that.
Input xml:
<world>
<country>
<name>USA</name>
<code>001</code>
<category type="developed" scheme="level1"/>
<category type="rich" scheme="level2"/>
</country>
<country>
<name>UK</name>
<code>044</code>
<category type="developed" scheme="level1"/>
<category type="rich" scheme="level2"/>
</country>
<country>
<name>LATVIA</name>
<code>371</code>
<category type="developed" scheme="level1"/>
</country>
<country>
<name>BHUTAN</name>
<code>975</code>
<category type="developing" scheme="level1"/>
</country>
</world>
Desired Output:
<world>
<developed>
<rich>
<country>
<name>USA</name>
<code>001</code>
</country>
<country>
<name>UK</name>
<code>044</code>
</country>
</rich>
<country>
<name>LATVIA</name>
<code>371</code>
</country>
</developed>
<developing>
<country>
<name>BHUTAN</name>
<code>975</code>
</country>
</developing>
</world>