[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Grouping problem?
Subject: Re: [xsl] Grouping problem? From: "Simon Kelly" <kelly@xxxxxxxxxx> Date: Wed, 23 Apr 2003 11:37:35 +0200 |
Damn it again!! Here is the tail recursion version!! <xsl:template match="ele"> <xsl:choose> <xsl:when test="position() = 1"> <xsl:variable name="count" select="sum(./@sum)" /> </xsl:when> <xsl:when test="$count < 10"> <xsl:choose> <xsl:when test="($count + sum(./@sum)) >= 10"> <br/> <xsl:variable name="count" select="sum(./@sum)" /> </xsl:when> <xsl:otherwise> <xsl:variable name="count" select="$count + sum(./@sum)" /> </xsl:otherwise> </xsl:choose> <xsl:otherwise> <br /> <xsl:variable name="count" select="sum(./@sum)" /> </xsl:otherwise> </xsl:choose> <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template> Cheers Simon ----- Original Message ----- From: "Simon Kelly" <kelly@xxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, April 23, 2003 11:25 AM Subject: Re: [xsl] Grouping problem? > Damn. > > I think I got something wrong with the <xsl:apply-templates > select="node()|@*" /> line. I just wanted to pass in the next sibling not > the entire node set. And I'm not 100% sure this isn't going to overflow on > very large node sets either. > > Cheers > > Simon > > > ----- Original Message ----- > From: "Simon Kelly" <kelly@xxxxxxxxxx> > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > Sent: Wednesday, April 23, 2003 11:13 AM > Subject: Re: [xsl] Grouping problem? > > > > Hi Benjamin, > > > > I can't actually test this solution as I don't use saxon, but if you can > > then this may work out ok. > > > > > > Up the top somewhere define an assignable variable > > > > <xsl:variable name="count" select="0" saxon:assignable="yes" /> > > > > then > > > > <xsl:template match="/root"> > > <xsl:apply-templates /> > > </xsl:template> > > > > <xsl:template match="ele"> > > <xsl:choose> > > <xsl:when test="position() = 1"> > > <xsl:variable name="count" select="sum(./@sum)" /> > > <xsl:copy> > > <xsl:apply-templates select="node()|@*" /> > > </xsl:copy> > > </xsl:when> > > <xsl:when test="$count < 10"> > > <xsl:choose> > > <xsl:when test="($count + sum(./@sum)) >= 10"> > > <br/> > > <xsl:variable name="count" select="sum(./@sum)" /> > > <xsl:copy> > > <xsl:apply-templates select="node()|@*" /> > > </xsl:copy> > > </xsl:when> > > <xsl:otherwise> > > <xsl:variable name="count" select="$count + sum(./@sum)" /> > > <xsl:copy> > > <xsl:apply-templates select="node()|@*" /> > > </xsl:copy> > > </xsl:otherwise> > > </xsl:choose> > > <xsl:otherwise> > > <br /> > > <xsl:variable name="count" select="sum(./@sum)" /> > > <xsl:copy> > > <xsl:apply-templates select="node()|@*" /> > > </xsl:copy> > > </xsl:otherwise> > > </xsl:choose> > > </xsl:template> > > > > > > It's a bit long winded but it should work. The last <xsl:otherwise /> in > > the main <xsl:choose /> takes care of any first nodes that are greater > than > > 10. This should also work for any ele grouping like > > > > <root> > > <set val="1"> > > <ele sum="1" /> > > ... > > <ele sum="n" /> > > </set> > > <set val="N"> > > <ele sum="2" /> > > ... > > <ele sum="N" /> > > </set> > > </root> > > > > with a minor mod to the calling template. > > > > Cheers > > > > Simon > > > > > > ----- Original Message ----- > > From: "Benjamin Farrow" <lovinjess@xxxxxxxxxxx> > > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > > Sent: Tuesday, April 22, 2003 9:06 PM > > Subject: [xsl] Grouping problem? > > > > > > > All, > > > I don't know how to explain my problem in words very concisely, so > I'll > > > try with a simplified example. > > > > > > SourceXML: > > > <root> > > > <ele sum="3"/> > > > <ele sum="4"/> > > > <ele sum="2"/> > > > <ele sum="10"/> > > > <ele sum="7"/> > > > <ele sum="5"/> > > > <ele sum="1"/> > > > <ele sum="2"/> > > > </root> > > > > > > Desired Output: > > > <root> > > > <ele sum="3"/> > > > <ele sum="4"/> > > > <ele sum="2"/> > > > <br/> <!-- next element makes total greater than 10 --> > > > <ele sum="10"/> > > > <br/> <!-- next element makes total greater than 20 --> > > > <ele sum="7"/> > > > <br/> <!-- next element makes total greater than 30 --> > > > <ele sum="5"/> > > > <ele sum="1"/> > > > <ele sum="2"/> > > > </root> > > > > > > I'm trying to break apart the ele element when the sum total of > preceding > > > siblings and self is greater than the increment of 10 by putting an > > element > > > to denote the break. > > > > > > I've tried some crazy tests with mod and div and I've looked over the > > > Muenchian grouping, but I still can't come up with a way to arbitrarily > > set > > > the break points. I know there is a solution and I get close, but I > just > > > can't get around it. > > > > > > Here is my template (also have the standard identity template) with > which > > > I'm trying to get this working. I just can't figure out the if test for > > > this though. > > > > > > XSL: > > > <xsl:template match="ele"> > > > <xsl:variable name="sum" > > > select="sum(preceding-sibling::ele/@sum|@sum)"/> > > > <xsl:if test="$sum > (floor($sum div 10) * 10)"> > > > <br/> > > > </xsl:if> > > > <xsl:copy> > > > <xsl:apply-templates select="node()|@*"/> > > > </xsl:copy> > > > </xsl:template> > > > > > > Thanks in advance, > > > Benjamin > > > > > > > > > _________________________________________________________________ > > > MSN 8 with e-mail virus protection service: 2 months FREE* > > > http://join.msn.com/?page=features/virus > > > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > > > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping problem?, Simon Kelly | Thread | Re: [xsl] Grouping problem?, Benjamin Farrow |
Re: [xsl] Grouping problem?, Simon Kelly | Date | RE: [xsl] Character entities in att, Edward . Middleton |
Month |