xsl-list
[Top] [All Lists]

RE: Re: Grouping problem?

2003-04-22 16:33:05
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(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Lars Huttar
Sent: Wednesday, 23 April 2003 10:10
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] 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



<Prev in Thread] Current Thread [Next in Thread>