So I'm trying to solve a problem in xslt which I would normally know how to do in an imperative language. I'm adding cells to a table from a list of xml elements, standard stuff. So:
<some-elements>
<element>"the"</element>
<element>"minds"</element>
<element>"of"</element>
<element>"Douglas"</element>
<element>"Hofstadter"</element>
<element>"and"</element>
<element>"Luciano"</element>
<element>"Berio"</element>
</some-elements>
However, I want to cut off one row and start a new one after a certain character maximum has been reached. So say I allow at the most, 20 characters per row. I'd end up with this:
<table>
<tr>
<td>"the"</td>
<td>"minds"</td>
<td>"of"</td>
<td>"Douglas"</td>
</tr>
<tr>
<td>"Hofstadter"</td>
<td>"and"</td>
<td>"Luciano"</td>
</tr>
<tr>
<td>"Berio"</td>
</tr>
</table>
In an imperative language, I'd append the elements to a row while adding each elements string-count to some mutable variable. When that variable exceeded 20, I'd stop, build a new row, and rerun the whole process (starting at the stopped element) on that row after returning the string-count to zero. However, I can't change variable values in XSLT. This whole stateless, function evaluation thing is throwing me for a loop.