Tempore 20:39:42, die Friday 18 February 2005 AD, hinc in foro {comp.text.xml} scripsit bearclaws <go**********@bencannon.com>:
I am looping through a list of categories and want to display the list
horizontally (instead of vertically). I want to create a single row
with 4 list items in each cell of the row.
<table border="1">
<tr>
<xsl:for-each select="category">
<!-- START CELL & LIST -->
<xsl:if test="position() = 1">
<td><ul>
</xsl:if>
<!-- LIST CATEGORY NAME -->
<li><xsl:value-of select="@name"/></li>
<!-- IF 4 LISTED: CLOSE LIST/CELL AND START NEW CELL -->
<xsl:if test="position() mod 4 = 0 and position() != last()">
</ul></td><td><ul>
</xsl:if>
<!-- CLOSE CELL IF LAST ITEM -->
<xsl:if test="position() = last()">
</ul></td>
</xsl:if>
</xsl:for-each>
</tr>
</table>
Hi,
Firstly, XSLT is written in XML. This document snippet is certainly not well-formed xml and will therefore never pass through parse stage.
Secondly, the algorithm you're trying to express cannot work in XSLT. In Xslt you can't create tags; you create nodes. These creations are atomic and cannot possibly be split in two halves.
The solution to your problem is grouping.
Here's one example of working code:
<table border="1">
<tr>
<xsl:for-each select="category[(position() -1) mod 4 = 0]">
<td><ul>
<xsl:for-each select=". | following-sibling::category[position() < 4]">
<li><xsl:value-of select="@name"/></li>
</xsl:for-each>
</ul></td>
</xsl:for-each>
</tr>
</table>
regards,
--
Joris Gillis (
http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Quot capita, tot sententiae" - Terentius , Phormio 454