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

Re: Efficently transposing tokenized data

Subject: Re: Efficently transposing tokenized data
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Wed, 05 Nov 2008 15:22:38 +0100
Re:  Efficently transposing tokenized data
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="."/>
  <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?

Michael Ludwig

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.