[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Re: Grouping problem?
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 > 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()>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
|
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
|