I have an xml, simplified version is below. I need to sort variable elements by name subelements.
<task>
<name>tsk name</name>
<id>123</id>
<agent />
<variable>
<name>var 687</name>
<value>3</value>
<chld>hgkj</chld>
</variable>
<variable>
<name>var 246</name>
<value>2</value>
<chld>khgkj</chld>
</variable>
<variable>
<name>var 296</name>
<value>9</value>
<chld>fjhgf</chld>
</variable>
</task>
I need to have variable element with name subelement with value 246 first, variable element with name subelement with value 296 second and variable element with name subelement with value 687 last. I know how to sort elements but I do not know how to sort them by certain subelements. I also have no attributes to sort the variable elements by. Would anybody help me?