As an addition to my orginal post Group/merge childs of same nodes in xml/xslt I ran into the problem of having that structure repeated multiple times for different nodes (wihtin nodes higher in the hierarchy) e.g.,
<Collection>
<Questionnaire Name="Preferences" VersionID="3QW">
<Subject ID="2355">
<EventData Name="First Part">
<FormData Name="Past">
<GroupData ID="xxx" Key="4" Temp="yyy">
<ItemData ID="zzz" Value="3"/>
</GroupData>
<GroupData ID="xxx" Key="4" Temp="yyy">
<ItemData ID="qqq" Value="4"/>
</GroupData>
...
</FormData>
<FormData Name="Present">
<GroupData ID="yyy" Key="9" Temp="yyy">
<ItemData ID="www" Value="32"/>
</GroupData>
...
</FormData>
</EventData>
<EventData Name="SecondPart">
...
</EventData>
</Subject>
<Subject ID="9812">
...
</Subject>
</Questionnaire>
</Collection>
After trying variations on the suggestions I reveived and some other things I am stuck. I think it has something to do with multiple levels (and GroupData being spread over upper/grandparent nodes in which it will be a child) and then it possiblly does not have unique IDs anymore. So how can I get the childs of each GroupData node into one GroupData node (matched on ID and sometimes Key, since the latter is not always present)? Note: The same GroupData nodes (with corresponding attributes) must be merged into one GroupData node in each FormData node.