I have XML that contains sibling nodes that have identical attribute values, but have different contents. This occurs at both the parent and the child level, as follows:
<myxml>
<a myattr="valuetop1">
<b myattr="valuechild1">
<c>Stuff1</c>
<c>Stuff2</c>
</b>
</a>
<a myattr="valuetop1">
<b myattr="valuechild2">
<c>Stuff3</c>
</b>
</a>
<a myattr="valuetop1">
<b myattr="valuechild2">
<c>Stuff4</c>
</b>
</a>
<a myattr="valuetop1">
<b myattr="valuechild2">
<c>Stuff5</c>
<c>Stuff6</c>
</b>
</a>
<a myattr="valuetop2">
<b myattr="valuechild1">
<c>Stuff1</c>
</b>
</a>
<a myattr="valuetop2">
<b myattr="valuechild3">
<c>Stuff2</c>
</b>
</a>
<a myattr="valuetop2">
<b myattr="valuechild2">
<c>Stuff3</c>
<c>Stuff2</c>
</b>
</a>
<a myattr="valuetop2">
<b myattr="valuechild2">
<c>Stuff4</c>
</b>
</a>
</myxml>
If there are nodes with identical attribute values that exist at the same level, I want to combine their contents under a single instance of that node. In other words, I'm looking for a neat hierarchy like this:
<myxml>
<a myattr="valuetop1">
<b myattr="valuechild1">
<c>Stuff1</c>
<c>Stuff2</c>
</b>
<b myattr="valuechild2">
<c>Stuff3</c>
<c>Stuff4</c>
<c>Stuff5</c>
<c>Stuff6</c>
</b>
</a>
<a myattr="valuetop2">
<b myattr="valuechild1">
<c>Stuff1</c>
</b>
<b myattr="valuechild3">
<c>Stuff2</c>
</b>
<b myattr="valuechild2">
<c>Stuff3</c>
<c>Stuff2</c>
<c>Stuff4</c>
</b>
</a>
</myxml>
The catch is that I don't know what the values of valuetopx or valuechildx will be. I've been banging my head over this one for a couple of days, but can't get my brain around it.