I am new to XSLT and changing it manually will take a lot of time.
<GroupData ID="xxx" Key="4" Temp="yyy">
<ItemData ID="zzz" Value="3"/>
</GroupData>
<GroupData ID="xxx" Key="4" Temp="yyy">
<ItemData ID="www" Value="1982"/>
</GroupData>
I want to have the childs of these multiple GroupData nodes within the same group, i.e.,
<GroupData ID="xxx" Key="4" Temp="yyy">
<ItemData ID="zzz" Value="3"/>
<ItemData ID="www" Value="1982"/>
</GroupData>
So I need to merge/combine/match them on both GroupData's ID and Key attributes (these vary within the file). Also some do not have a Key attribute. How can I do that? I read some other threads (for example, in C# but I don't have that at my disposal) and I checked W3 schools but these are very basic examples. I am using the latest XML Tools 2.3.2 r908 unicode (beta4) for Notepad++ to apply possible transformations (do not know whether it supports XSLT2.0 or XSLT1.0).
Edit: After trying the suggestions below and various things I am stuck since it has multiple levels and possiblly does not have unique IDs:
...
If it is XSLT 2.0 then you can use a nested
<xsl:for-each-group>
(I'm assuming your input file has a root element
<Groups>
and uses no namespaces).If it's XSLT 1.0 then you need to use Muenchian Grouping:
Here I'm doing a single grouping pass based on both the ID and Key attributes by creating a synthetic
key
value of{ID}___{Key}
.This XSLT 1.0 transformation:
when applied on this XML document:
produces the wanted, correct result:
Explanation:
Proper use of the Muenchian grouping method and the identity rule.