[xsl] Grouping problem?

Subject: [xsl] Grouping problem?
From: "Benjamin Farrow" <lovinjess@xxxxxxxxxxx>
Date: Tue, 22 Apr 2003 12:06:02 -0700
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 &gt; (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



Current Thread