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

RE: Grouping problem?

Subject: RE: Grouping problem?
From: "Conal Tuohy" <conalt@xxxxxxxxxxxxxxx>
Date: Wed, 23 Apr 2003 09:26:19 +1200
RE:  Grouping problem?
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


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.