[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Grouping problem?

Subject: Re: Grouping problem?
From: "Simon Kelly" <kelly@xxxxxxxxxx>
Date: Wed, 23 Apr 2003 11:13:57 +0200
xsl sum count
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:  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 &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
>
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.