[xsl] Efficently transposing tokenized data

Subject: [xsl] Efficently transposing tokenized data
From: Beldaz Jalfrezi <beldazj@xxxxxxxxxxxx>
Date: Tue, 4 Nov 2008 15:13:01 -0800 (PST)
Hi XSL-List members,

I have been learning my way around XSLT (2.0) over the
past couple of weeks, principally using Saxon-B 9.1. I have an immediate need
to transform existing XML data, initially to HTML. The XML contains, similar
to SVG, space-tokenized numerical data held within attributes. What I am
having trouble understanding is how to transform several nodes with such data
into individual columns of data.

The XML is like this:
<Line title="Line 1" data="0.1 0.4 0.6 0.4 0..8" />
title="Line 2" data="0.4 0.2 0.5 1.4 3.8" />

There can be any
number of <Line> nodes (typically 3 or 4) and the number of values (samples)
in each data attribute for each <Line> must match the samples attribute of the
parent <MultiLine> node. The number of samples can be very long, typically
several thousand. At present this is the data that I am being supplied, so
regardless of any shortcomings of the structure (although suggestions for
improvement are welcome) I am stuck with it.

I want to transform such data
into, e.g., HTML columns, like:
<TH>Line 1</TH><TH>Line 2</TH>

I have seen similar
questions where people have wanted to transpose HTML table data, but the
problem here is that the input data has to be tokenized. I can output the data
sequentially for each Line with a template such as:
<TR><TH><xsl:value-of select="@title" /></TH><TR>
<xsl:for-each select="tokenize(@data,' ')">
<xsl:value-of select="position()" />
<xsl:value-of select="." />

To format
the data as adjacent columns the only approach I can think of is a for-each
loop over the number of samples, and in each case call
index-at(tokenize(../Line[n]/@data, ' '), position()) for each Line. But this
looks horribly inefficient, since I appear to be tokenizing every @data
attribute repeatedly, presumably giving complexity O(count(Line)*samples^2).
What would be far more preferable is to tokenize all the lines, and then at
each index obtain the appropriate value from each sequence. But I have no idea
how to do that in XSLT.

I have spent at least a day trying to solve this
conumdrum, so if anyone has any suggestions I would be very grateful.



      Search 1000's of available singles in your area at
the new Yahoo!7 Dating. Get Started

Current Thread