xsl-list
[Top] [All Lists]

RE: Grouping problem?

2003-04-22 14:26:19
Lars Huttar wrote:

I like it!  Interesting way to form a group.

It might be slow for large source documents, maybe order(N*N)
where N is the number of ele elements (because for each element you
have to sum all preceding elements); but I can't see a way
around that... unless you want to recursively loop through
the elements,
keeping a running total.

Like this:

<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:variable name="first-ele" select="$ele-list[1]"/>
                <xsl:variable name="new-count" select="$count + 
$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 mod 
10"/>
                </xsl:call-template>
        </xsl:if>
</xsl:template>

As you say, Lars, this approach would probably be a lot quicker for large
documents.

Cheers!

Con


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



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