|
[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Grouping problem?
Subject: Re: Grouping problem?
From: "Benjamin Farrow" <lovinjess@xxxxxxxxxxx>
Date: Tue, 22 Apr 2003 12:51:35 -0700
|
Well perhaps I've found a solution...it appears to be working anyhow. Any
comments would be welcome.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="groupByTen"
match="ele"
use="ceiling(sum(preceding-sibling::ele/@sum|@sum) div 10)"/>
<xsl:template match="/">
<xsl:apply-templates select="node()|@*"/>
</xsl:template>
<xsl:template match="ele">
<xsl:variable name="sum"
select="sum(preceding-sibling::ele/@sum|@sum)"/>
<xsl:if test="generate-id(key('groupByTen',ceiling($sum div 10))[1]) =
generate-id(.) and
position() != 1">
<br/>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
From: "Benjamin Farrow" <lovinjess@xxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Grouping problem?
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 > (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
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
| RSS 2.0 |
|
| Atom 0.3 |
|
|