The first for-each-group almost works. It finds everything that I need it to find, except some of the sachbegriff nodes (i.e. it finds 47, but one is missing etc.). When I a do a second pass (another for-each-group) explicitly asking for those nodes, I get them. (Of course, now I have some nodes twice and the order is messed up). Any ideas why I don't get them the first time around?
Tried with Saxon-HE .NET 9.x and 10.2 now.
<xsl:for-each-group select="/museumPlusExport/sammlungsobjekt[@objId eq $id]/*" group-by="string()">
<xsl:sort select="name()" />
<xsl:apply-templates select="."/>
</xsl:for-each-group>
<xsl:for-each-group select="/museumPlusExport/sammlungsobjekt[@objId eq $id]/sachbegriff" group-by="string()">
<xsl:apply-templates select="."/>
</xsl:for-each-group>
SOLUTION/SOLVED based on Martin Honnen's answer/explanation below XSLT 2.0
<xsl:for-each-group select="/museumPlusExport/sammlungsobjekt[@objId eq $id]/*"
group-by="concat(name(), '|', string())">
<xsl:sort select="name()" />
<xsl:variable name="name" select="name()"/>
<xsl:apply-templates select="."/>
</xsl:for-each-group>
XSLT 3.0
<xsl:for-each-group select="/museumPlusExport/sammlungsobjekt[@objId eq $id]/*"
composite="yes" group-by="node-name(), string()">
<xsl:sort select="name()" />
<xsl:variable name="name" select="name()"/>
<xsl:apply-templates select="."/>
</xsl:for-each-group>