PDA

View Full Version : Using XSL Looping & Conditionals (is this possible?)


Skizzler
07-24-2006, 09:15 PM
Hey all, I've gotten some great help here before, and now I've come across another snag at work. Figuring it out could take me awhile, but I think somebody experienced with XSL might be able to help out quickly.

I've got some xml files that I need to change the format of, but it seems to be sort of "non-standard" in terms of how I need to change it - I need to go through groups of the stimulus element in threes to create clusters of their content and context values.

I just "discovered" XSL today and that it could complete the task I need to do, but I'm not yet experienced using it. I am having a bit of trouble piecing together the loop & conditions necessary to complete this transformation (described below).

Here's the initial file format:

<stimulus>
<id>0</id>
<content>%E4%B8%80</content>
<type>text</type>
<context>Hanzi</context>
</stimulus>

<stimulus>
<id>1</id>
<content>yi1</content>
<type>text</type>
<context>Pinyin</context>
</stimulus>

<stimulus>
<id>2</id>
<content>one</content>
<type>text</type>
<context>English</context>
</stimulus>

<stimulus>
<id>3</id>
<content>%E4%B8%A8</content>
<type>text</type>
<context>Hanzi</context>
</stimulus>

<stimulus>
<id>4</id>
<content>gun3</content>
<type>text</type>
<context>Pinyin</context>
</stimulus>

<stimulus>
<id>5</id>
<content>line</content>
<type>text</type>
<context>English</context>
</stimulus>
...
and so on for a few hundred stimuli.

So the important thing here is that every three stimuli forms a "cluster" - the English, Hanzi and Pinyin are all referring to the same concept. Basically what I need to do is go through by threes, and transform to a sheet like this:


<cluster>
<Hanzi>%E4%B8%80</Hanzi>
<Pinyin>yi1<Pinyin>
<English>one</English>
</cluster>
<cluster>
<Hanzi>%E4%B8%A8</Hanzi>
<Pinyin>gun3</Pinyin>
<English>line</English>
</cluster>


So for every 3 elements of <stimulus> I need to make a new <cluster>, with each cluster containing <value of context>value of content</value of context>. I just don't know how to use the modulus in XSL or have it create a new <cluster> only on every 3rd <stimulus>. Thanks for anyone who's read this far, hopefully somebody understands what I'm trying to do and can give some input. :)