[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Grouping- Any Better Suggestion?
Subject: Re: [xsl] Grouping- Any Better Suggestion? From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx> Date: Thu, 13 Oct 2011 14:23:25 -0400 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping- Any Better Sugg, Vasu Chakkera | Thread | [xsl] XSL:FO Vs Reporting Tools, Vasu Chakkera |
Re: [xsl] XSL:FO Vs Reporting Tools, G. Ken Holman | Date | RE: [xsl] Status of schematron mail, Norm Birkett |
Month |
Keywords