I found a similar question to mine, but couldn't figure out a way for my issue.
I have an XML as follows
<name>
<text class="002. AB vs BC"> Sample</text>
<text class="003. DC vs BC"> Sample</text>
<text class="004. CD vs BC"> Sample</text>
<text class="005. AB vs BC"> Sample</text>
<text class="006. AB vs BC"> Sample</text>
<text class="007. EF vs BC"> Sample</text>
<text class="008. CD vs BC"> Sample</text>
<text class="009. DC vs BC"> Sample</text>
<text class="010. AB vs BC"> Sample</text>
<text class="011. EF vs BC"> Sample</text>
<text class="012. AB vs BC"> Sample</text>
</name>
And I need to group all the nodes with similar first word in class attribute as follows
<name>
<group name="AB">
<text class="002. AB vs BC"> Sample</text>
<text class="005. AB vs BC"> Sample</text>
<text class="006. AB vs BC"> Sample</text>
<text class="010. AB vs BC"> Sample</text>
<text class="012. AB vs BC"> Sample</text>
</group>
<group name="EF">
<text class="007. EF vs BC"> Sample</text>
<text class="011. EF vs BC"> Sample</text>
</group>
<group name="CD">
<text class="008. CD vs BC"> Sample</text>
<text class="004. CD vs BC"> Sample</text>
</group>
<group name="DC">
<text class="003. DC vs BC"> Sample</text>
<text class="009. DC vs BC"> Sample</text>
</group>
</name>
How to achieve this?
See Question&Answers more detail:os