I need an XSLT template to transform this type of XML input:
<vector_set>
<vector channel="1">
1 2 2 1 1 2
2 5 4 4 3 1
</vector>
<vector channel="2">
0 1 0 4 1 2
5 4 1 1 2 3
</vector>
<vector channel="3">
2 1 3 2 2 7
8 1 8 8 9 10
</vector>
</vector_set>
into this XML output:
<table>
<row>
<col>Channel 1</col><col>Channel 2</col><col>Channel 3</col>
</row>
<row><col>1</col><col>0</col><col>2</col></row>
<row><col>2</col><col>1</col><col>1</col></row>
<row><col>2</col><col>0</col><col>3</col></row>
<row><col>1</col><col>4</col><col>2</col></row>
<row><col>1</col><col>1</col><col>2</col></row>
<row><col>2</col><col>2</col><col>7</col></row>
<row><col>2</col><col>5</col><col>8</col></row>
<row><col>5</col><col>4</col><col>1</col></row>
<row><col>4</col><col>1</col><col>8</col></row>
<row><col>4</col><col>1</col><col>8</col></row>
<row><col>3</col><col>2</col><col>9</col></row>
<row><col>1</col><col>3</col><col>10</col></row>
</table>
The vector elements are generally much larger than what's shown-
they may have hundreds or thousands of tab-delimited numbers, with
line breaks occasionally. The basic problem is to transpose
the input data so it's arranged in columns by channel. I can
tokenize the vectors and recursively pick off each data point,
but I can't think of a way to do it simultaneously for each
channel (i.e. one output row at a time), without repeatedly
calling the recursive template. That would make it scale
extremely badly. If the vector data points were all individual
elements, I could just refer to them by position, but they aren't.
I was thinking of a tokenizer that outputted the first data
point, then returned the rest of the string for later, but I don't
see how to save the new string for next time, after going
through the other channels.
Any slick XSLT ideas? The number of channels is variable,
but is always relatively small. A good answer would be
working XSLT code that would transform the above input, and
scale well when the vectors have thousands of data points. |