Click to See Complete Forum and Search --> : Need help with XSLT - grouping tags


Alsvha
June 2nd, 2009, 03:19 AM
I have a problem I'm looking to solve with XSLT, but I'm a bit stumped at how to implement the syntax.

I basically have a XML file with a structure narrowed down to this:

<ITEM>
<NAMEVALUE>
<NAME>From1</NAME>
<VALUE>From1 Value</VALUE>
</NAMEVALUE>
<NAMEVALUE>
<NAME>From2</NAME>
<VALUE>From2 Value</VALUE>
</NAMEVALUE>
<NAMEVALUE>
<NAME>Price1</NAME>
<VALUE>Price1 Value</VALUE>
</NAMEVALUE>
<NAMEVALUE>
<NAME>Price2</NAME>
<VALUE>Price2 Value</VALUE>
</NAMEVALUE>
.
.
.
.
</ITEM>

(I can't change the format of the delivered file).

I would like to transform it into something equivalent to:

<Prices>
<Price from="From1 Value">Price1 Value</Price>
<Price from="From2 Value">Price2 Value</Price>
</Prices>


I am running scripts in my XSLT file, and can most likely fix it using scripts but I was wondering if it would be possible to either use more pure XSL syntaxt to solve this problem.

Any advice?

jkmyoung
June 2nd, 2009, 09:16 AM
How are you determining which tags link up to each other? Is it like a 2 column thing, where all of 1 value appears first, then all of the 2nd value?

Alsvha
June 2nd, 2009, 11:42 AM
They match up based on the "number" in the Name tag value. From1 matches to Price1 and (of course) I can't be guaranteed that they'll always come in the proper pair order, so I can't just match one and count on the next to come in the next namevalue pair.

So Price2 can come before From1 which comes before From2 and so on.... it is a messed up format, but it is what I have to work with and unfortunately - I have difficulty in finding XSLT syntax to solve it, so I likely have to go another route for my transformation (perhaps a manual transformation or script it).

Alsvha
June 4th, 2009, 03:24 AM
Giving up on the XSLT of this and trying a manual code based transform through streams instead. Looks to perform just as well, but requires more coding from me.