[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2011-08-15 15:38 +0200, graham.heath wrote:
Do you have to use groups?
Below is an XSLT 1.0 solution that assumes no duplicate pairings that I hope helps. Of course it would also work with XSLT 2.0.
It relies on the XPath comparison of two node sets walking through the members of both node sets repeatedly making comparisons: you need only look forward to a pair that doesn't include any player that is in the given pair.
. . . . . . . . Ken
Re: [xsl] Grouping problem
Subject: Re: [xsl] Grouping problem From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 15 Aug 2011 17:36:52 -0500 |
At 2011-08-15 15:38 +0200, graham.heath wrote:
I have an xml grouping problem that has so far defeated me.
...
is it possible to group pairs such that each player occurs only once in each group?
...
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..
Do you have to use groups?
Below is an XSLT 1.0 solution that assumes no duplicate pairings that I hope helps. Of course it would also work with XSLT 2.0.
It relies on the XPath comparison of two node sets walking through the members of both node sets repeatedly making comparisons: you need only look forward to a pair that doesn't include any player that is in the given pair.
. . . . . . . . Ken
t:\ftemp>type hector.xml <?xml version="1.0" encoding="UTF-8"?> <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>
t:\ftemp>call xslt hector.xml hector.xsl <?xml version="1.0" encoding="utf-8"?><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><table><pair> <player>player1</player> <player>player4</player> </pair><pair> <player>player2</player> <player>player3</player> </pair></table> t:\ftemp>type hector.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:for-each select="/*/pair"> <xsl:if test="following-sibling::pair[not(player=current()/player)]"> <table> <xsl:copy-of select="."/> <xsl:copy-of select="following-sibling::pair[not(player=current()/player)]"/> </table> </xsl:if> </xsl:for-each> </xsl:template>
</xsl:stylesheet> t:\ftemp>rem Done!
-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping problem, graham.heath | Thread | [xsl] using OR in a group-ending-wi, Jeff Wilson |
Re: [xsl] Changing namespaces, David Carlisle | Date | Re: [xsl] Grouping and then more gr, G. Ken Holman |
Month |