xsl-list
[Top] [All Lists]

Re: [xsl] Grouping problem

2011-08-15 10:38:04
Ok I've hacked this together, it gets all possible combos then filters
them down:

<xsl:variable name="pairs" select="//pair"/>

<xsl:variable name="combos" as="element(table)*">
        <xsl:for-each select="$pairs">
                <xsl:variable name="outer" select="."/>
                <xsl:for-each select="$pairs[not(. is $outer)]">
                        <table>
                                <xsl:for-each select="$outer, .">
                                        <xsl:sort select="."/>
                                        <xsl:copy-of select="."/>
                                </xsl:for-each>
                        </table>
                </xsl:for-each>
        </xsl:for-each>
</xsl:variable>

<xsl:template match="/">
        <root>
                <xsl:for-each-group
select="$combos[count(distinct-values(.//player)) = 4]" group-by=".">
                        <xsl:copy-of select="."/>
                </xsl:for-each-group>
        </root>
</xsl:template>




On 15 August 2011 16:00, graham.heath <graham(_dot_)heath(_at_)gmail(_dot_)com> 
wrote:
Okay Andrew,

I forgot to write out all the permutations :-)
You could say that the example was cut down a tad too far..
<table>

<pair>
     <player>player1</player>
     <player>player4</player>
</pair>
<pair>
     <player>player2</player>
     <player>player3</player>
</pair>
</table>



In your example output, where should the pair:

<pair>
      <player>player1</player>
      <player>player4</player>
</pair>

go?



On 15 August 2011 14:38, 
graham.heath<graham(_dot_)heath(_at_)gmail(_dot_)com>  wrote:

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




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or 
e-mail:<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





-- 
Andrew Welch
http://andrewjwelch.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>