I want to group the following XML:
<DataSet>
<FirstNode>
<UniqueKey>111</UniqueKey>
<OtherKey>552</OtherKey>
</FirstNode>
<FirstNode>
<UniqueKey>123</UniqueKey>
<OtherKey>552</OtherKey>
</FirstNode>
<FirstNode>
<UniqueKey>154</UniqueKey>
<OtherKey>553</OtherKey>
</FirstNode>
<SecondNode>
<FirstNodeKey>111</FirstNodeKey>
</SecondNode>
<SecondNode>
<FirstNodeKey>123></FirstNodeKey>
</SecondNode>
<SecondNode>
<FirstNodeKey>154></FirstNodeKey>
</SecondNode>
</DataSet>
I want to produce the following xml with XSLT:
<DataSet>
<FirstNode>
<UniqueKey>111</UniqueKey>
<OtherKey>552</OtherKey>
</FirstNode>
<FirstNode>
<UniqueKey>123</UniqueKey>
<OtherKey>552</OtherKey>
</FirstNode>
<SecondNode>
<FirstNodeKey>111</FirstNodeKey>
</SecondNode>
<SecondNode>
<FirstNodeKey>123></FirstNodeKey>
</SecondNode>
</DataSet>
<DataSet>
<FirstNode>
<UniqueKey>154</UniqueKey>
<OtherKey>553</OtherKey>
</FirstNode>
<SecondNode>
<FirstNodeKey>154></FirstNodeKey>
</SecondNode>
</DataSet>
Basically I want to group the FirstNodes by the OtherKey first, and then group by the UniqueKey and FirstNodeKey. Then each should be enclosed in <DataSet></DataSet>
. Can I do this by using grouping?
Thanks in advance for your help!
It seems you simply want to group the
FirstNode
elements by theOtherKey
child and then reference anySecondNode
elements based oncurrent-group()/UniqueKey
:That is XSLT 3 working with Saxon 9.8 (example at https://xsltfiddle.liberty-development.net/3NzcBtw) or Altova 2018, for XSLT 2 you could spell out the
as
and of course if there are other nodes to process replace the
xsl:mode
declaration with the identity template.