|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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 > 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 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
|
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
|

Cart








