Google Answers Logo
View Question
 
Q: need XSLT code to transpose white-space delimited vectors ( No Answer,   0 Comments )
Question  
Subject: need XSLT code to transpose white-space delimited vectors
Category: Computers > Programming
Asked by: formica34-ga
List Price: $40.00
Posted: 29 Dec 2004 12:33 PST
Expires: 29 Dec 2004 19:24 PST
Question ID: 448860
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.

Clarification of Question by formica34-ga on 29 Dec 2004 12:36 PST
I forgot to mention that I'm using MSXML2, ver. 4.  I'd prefer not to
use any non-XSLT scripting, but I can use the exslt.org extensions.

Clarification of Question by formica34-ga on 29 Dec 2004 19:24 PST
Actually, I figured it out.  I discovered the EXSLT tokenize template,
and the node-set function.  I can just set three channel variables to
the three tokenized strings, then use a for-each loop to output each
row.  I can use the node-set function to access the tree fragments
from the tokenization, which makes it easy to refer to a particular
one.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy