[xsl] Grouping problem

Subject: [xsl] Grouping problem
From: "graham.heath" <graham.heath@xxxxxxxxx>
Date: Mon, 15 Aug 2011 15:38:29 +0200
Hello mega brains,

I have an xml grouping problem that has so far defeated me.

Given the xml
<pairings>
<pair>
       <player>player1</player>
       <player>player2</player>
</pair>
<pair>
       <player>player1</player>
       <player>player3</player>
</pair>
<pair>
       <player>player1</player>
       <player>player4</player>
</pair>
<pair>
       <player>player2</player>
       <player>player3</player>
</pair>
<pair>
       <player>player2</player>
       <player>player4</player>
</pair>
<pair>
       <player>player3</player>
       <player>player4</player>
</pair>
</pairings>

is it possible to group pairs such that each player occurs only once in each group?
<table>
<pair>
       <player>player1</player>
       <player>player2</player>
</pair>
<pair>
       <player>player3</player>
       <player>player4</player>
</pair>
</table>
<table>
<pair>
       <player>player1</player>
       <player>player3</player>
</pair>
<pair>
       <player>player2</player>
       <player>player4</player>
</pair>
</table>

I was of the opinion that some form of xsl:for-each-group would suffice but have been unable to devise a group-by expression that works..
    <xsl:for-each-group select="pairings/pair" group-by="count(distinct-values(player))=1">
      <table>
        <xsl:apply-templates select="current-group() "/>
      </table>
    </xsl:for-each-group>

Many thanks

Hector

Current Thread