Using XSLT 1.0 I need to transform this:
<form>
<question NumOfColumns="3">
<title>Colors</title>
<answer>red</answer>
<answer>orange</answer>
<answer>yellow</answer>
<answer>green</answer>
<answer>blue</answer>
<answer>indigo</answer>
<answer>violet</answer>
</question>
</form>
into this:
<h2 class="question">Colors</h2>
<div class="answersrow">
<input type="checkbox" name="colors" value="red" id="red" /> <label for="red">red</label>
<input type="checkbox" name="colors" value="orange" id="orange" /> <label for="orange">orange</label>
<input type="checkbox" name="colors" value="yellow" id="yellow" /> <label for="yellow">yellow</label>
</div>
<div class="answersrow">
<input type="checkbox" name="colors" value="green" id="green" /> <label for="green">green</label>
<input type="checkbox" name="colors" value="blue" id="blue" /> <label for="blue">blue</label>
<input type="checkbox" name="colors" value="indigo" id="indigo" /> <label for="indigo">indigo</label>
</div>
<div class="answersrow">
<input type="checkbox" name="colors" value="green" id="green" /> <label for="green">green</label>
</div>
NumOfColumns in the question node tells how many columns to use when outputting answer divs. For each node, I can get its row using:
ceiling(position() div parent::*/@NumOfColumns)
This is working fine; i can output the correct integer. But I can't get the keys/grouping working, and I'm not sure where the problem is.
I thought the key would be:
<xsl:key name="answersrow" match="form/question/answer[ceiling( position() div parent::*/@NumOfColumns) = parent::*/@NumOfColumns]" use="." />
and then I could retrieve nodes with:
<xsl:for-each select="key('answersrow', answer)">
No luck. Anyone have a solution? Or is this not doable in XSLT 1.0?