Subject: [xsl] Grouping- Any Better Suggestion? From: Vasu Chakkera <vasucv@xxxxxxxxx> Date: Thu, 13 Oct 2011 09:53:33 +0100 |
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] Numbering similar nodes s, Mark | Thread | Re: [xsl] Grouping- Any Better Sugg, Andrew Welch |
Re: [xsl] Numbering similar nodes s, Mark | Date | Re: [xsl] Grouping- Any Better Sugg, Andrew Welch |
Month |