Re: [xsl] Efficently transposing tokenized data

Subject: Re: [xsl] Efficently transposing tokenized data
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Wed, 05 Nov 2008 15:22:38 +0100
Michael Kay schrieb:
(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="."/>
    <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"
  <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"/>
        <xsl:for-each select="Line">
          <th><xsl:value-of select="@title"/></th>
      <xsl:for-each-group select="$data-chain"
        group-by="position() mod $samples">
          <xsl:for-each select="current-group()">
            <td><xsl:value-of select="."/></td>

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?

Michael Ludwig

Current Thread