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

RE: Re: Grouping problem?

Subject: RE: Re: Grouping problem?
From: "Benjamin Farrow" <lovinjess@xxxxxxxxxxx>
Date: Wed, 23 Apr 2003 14:18:41 -0700
xslt cumulative sum
Thanks to all for their help and ideas. I don't know why I didn't look at recursion as a solution...

I don't think I fully understood what I wanted and maybe I'm still not 100% sure. :) So thanks for bearing with me and giving me possible solutions...

I'm still deciding if this is the right tool for the job. The documents I'm using are significantly larger than my sample (I'm grouping by a sum of 2000). This is the first step to my problem, so I've got it working now, but now I need to tackle the second. I'm using MSXML and VB for this project. I've modified the named template to be a match template and that seems to have improved the performance significantly.


Thanks again for all who helped,


Benjamin

From: "Conal Tuohy" <conalt@xxxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE:  Re: Grouping problem?
Date: Wed, 23 Apr 2003 11:33:05 +1200

Hi Lars. I think you're right about the correct definition of the problem.
So I still didn't have my conditions right.

Here's my 3rd version of the recursive solution, which now produces the same
output as Benjamin's.


I would guess that this recursive solution would be quicker (for documents
larger than a certain size), but on the other hand perhaps it could produce
stack-overflow problems on really large documents? As I understand it, using
tail-recursion is supposed to allow the XSLT interpreter to optimise the
recursion by converting to it a loop, without pushing stack frames ... but I
don't know how many processors actually implement this? Does anyone know? Is
my code below appropriate for this kind of optimisation?


http://www-106.ibm.com/developerworks/xml/library/x-xslrecur/?dwzone=xml#opt
4
http://info.astrian.net/jargon/terms/t/tail_recursion.html :-)

<xsl:template match="root">
	<xsl:copy>
		<xsl:call-template name="group-ele">
			<xsl:with-param name="ele-list" select="ele"/>
		</xsl:call-template>
	</xsl:copy>
</xsl:template>

<xsl:template name="group-ele">
	<xsl:param name="ele-list" select="/.."/>
	<xsl:param name="count" select="0"/>
	<xsl:if test="$ele-list">
		<xsl:if test="$count = 10">
			<br/>
		</xsl:if>
		<xsl:variable name="first-ele" select="$ele-list[1]"/>
		<xsl:variable name="new-count" select="$count mod 10 + $first-ele/@sum"/>
		<xsl:if test="$new-count &gt; 10">
			<br/>
		</xsl:if>
		<xsl:copy-of select="$first-ele"/>
		<xsl:call-template name="group-ele">
			<xsl:with-param name="ele-list" select="$ele-list[position()&gt;1]"/>
			<xsl:with-param name="count" select="$new-count"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Lars Huttar
> Sent: Wednesday, 23 April 2003 10:10
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Re: Grouping problem?
>
>
> Dimitre Novatchev wrote:
> > Unfortunately, this does not produce the right result in the
> > general case.
>
> I believe it does in the example data you gave, at least
> as I understand Benjamin's definition of the problem.
>
> > The result produced by your transformation is:
> >
> > <root>
> >   <ele sum="3"></ele>
> >   <ele sum="4"></ele>
> >   <ele sum="2"></ele>
> >   <br />
> >   <ele sum="10"></ele>
> >   <ele sum="1"></ele>
> >   <br />
> >   <ele sum="5"></ele>
> >   <ele sum="1"></ele>
> >   <ele sum="2"></ele>
> > </root>
> >
> > The second group above has a sum of 11.
>
> Benjamin's requirement was:
>
> >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.
>
> E.g. in the above data, a <br/> appears just before the cumulative sum
> would exceed 10, and again just before the cumulative sum would exceed
> 20.
> Benjamin was not saying that each group should total 10 or less.
>
> Not to discount the rest of your message...
>
> Lars
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


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




_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963



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.