Subject: Re: [xsl] Efficently transposing tokenized data|
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Wed, 05 Nov 2008 15:22:38 +0100
(2) Do a preprocessing pass to compute a sequence of NxM strings in one big sequence, then operate by indexing into this big sequence.
<xsl:for-each select="1 to xs:integer(@samples)"> <xsl:variable name="row" select="."/> <tr> <xsl:for-each select="1 to $columns"> <xsl:variable name="col" select="."/> <td><xsl:value-of select="$bigArray[(:some function of $row and $column, an exercise for the reader:)]
I've just done this as an after-lunch exercise before reading your answer. I decided to compute a big sequence and then apply xsl:for-each-group with a modulo expression to do the grouping.
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="MultiLine"> <xsl:variable name="data-chain" as="xs:string*" select="for $l in Line return tokenize( $l/@data, '\s')"/> <xsl:variable name="samples" select="@samples cast as xs:integer"/> <table> <tr> <xsl:for-each select="Line"> <th><xsl:value-of select="@title"/></th> </xsl:for-each> </tr> <xsl:for-each-group select="$data-chain" group-by="position() mod $samples"> <tr> <xsl:for-each select="current-group()"> <td><xsl:value-of select="."/></td> </xsl:for-each> </tr> </xsl:for-each-group> </table> </xsl:template> </xsl:stylesheet>
Assuming a large input, your approach looks more efficient to me as it avoids grouping where indexing into the list does the job.
Now I guess from previous answers on this list given to similar questions that this is all implementation-defined.
In spite of this, I'm asking whether that is all that can be said here or whether there is a rationale here to favor indexing over grouping when (a) processing time or (b) memory consumption are important?
|<- Previous||Index||Next ->|
|RE: [xsl] Efficently transposing to, Michael Kay||Thread||RE: [xsl] Efficently transposing to, Michael Kay|
|Re: [xsl] how to do this, Mukul Gandhi||Date||RE: [xsl] Efficently transposing to, Michael Kay|