How about generating a sequence with multiple keys for each item?
With your original code, replace group-by="area" with group-by="(area,
following-sibling::*[1]/area)" and use "current-grouping-key()"
instead of "area" when generating the header for each group.
-Brandon :)
On Thu, Oct 13, 2011 at 4:53 AM, Vasu Chakkera <vasucv@xxxxxxxxx> wrote:
> Dear All,
> I have a funny grouping issue, and I have a solution to that. I
> wondered if there were better ways to do it..
>
> The problem definition is as follows:
>
> I have a list of points in my XML and each point belongs to one area.
> I need to print a heading of the area and then put all the points
> underneath in a new line..
>
> example:
> xml has
> point1 - area A
> point2 - area A
> point3 - area A
> point4 - area B
> point5 - area B
> point6 - area B
> point7 - area B
> point8 - area C
> point9 - area C
> point10 - area C
>
> I wanted to print
>
> Area A
> ======
> Point 1
> Point 2
> Point 3
>
> Area B
> ======
> Point 4
> Point 5
> Point 6
>
> etc...
>
> I can do this easily by saying...
> <xsl:for-each-group select="//staticpoint" group-by="area">
> <hr/>
> <h1>AREA : <xsl:value-of select="area"/></h1>
>
>
> <xsl:for-each select="current-group()">
>
> <xsl:value-of select="point"/>
> <br/>
>
> </xsl:for-each>
>
>
>
> </xsl:for-each-group>
>
> I called this a little funny because What I want is that the last
> point in the the current group should allways be shown as the first in
> the second group. You can imagine this as the union area in the Venn
> diagram .. where a point can belong to two areas. the business says
> that at that point since the second area starts, technically it
> belongs to the second area.
>
> The solution i had was that I will regroup these points and have
> another attribute where I will add the value of the changing area to
> the last element in that group.
>
>
> <regroup>
>
> <xsl:for-each select="//staticpoint">
>
> <xsl:copy>
> <xsl:attribute name="group">
> <xsl:choose>
>
> <!-- last point , after which the area changes
-->
> <xsl:when test="not(area =
> following-sibling::staticpoint[1]/area)">
>
> <xsl:value-of
> select="following-sibling::staticpoint[1]/area"/>
> </xsl:when>
> <xsl:otherwise>
>
> <xsl:value-of select="area"/>
> </xsl:otherwise>
> </xsl:choose>
>
>
> </xsl:attribute>
>
>
>
> <xsl:copy-of select="node()"/>
> </xsl:copy>
>
>
> </xsl:for-each>
>
> </regroup>
>
> And then do a regular grouping on the staticpoint/@group
>
> Anybody has any better ideas?
>
> Vasu
|