Splitting XSL for-each data into 2 columns. Two Ways!
On my mission to find a way to split a for-each statements results into 2 columns I came across two ways. one to do horizontal, the other vertical. these are the examples. The vertical option was a modified version of the code on this page, thanks! http://overture21.com/forum/comments.php?DiscussionID=378
Display Horizontal
A B
C D
E F
Code
<xsl:for-each select="root/minimapproducts/item"> <li style="width: 45%;float: left;"> <a> <xsl:attribute name="href"> <xsl:value-of select="/root/gendermix/cat" />/<xsl:value-of select="@url"/> </xsl:attribute> <xsl:attribute name="title"> <xsl:value-of select="@name"/> </xsl:attribute> <xsl:value-of select="@name"/> </a> </li> </xsl:for-each>
Vertial Layout
A D
B E
C F
Code
<xsl:variable name="split" select="ceiling(count(/root/minimapproducts/item) div 2)" /> <ul class="mensLinks" style="width:45%; float:left;"> <xsl:for-each select="root/minimapproducts/item"> <xsl:if test="position() &lt;= $split"> <li> <a> <xsl:attribute name="href"> <xsl:value-of select="/root/gendermix/cat" />/<xsl:value-of select="@url"/> </xsl:attribute> <xsl:attribute name="title"> <xsl:value-of select="@name"/> </xsl:attribute> <xsl:value-of select="@name"/> </a> </li> </xsl:if> </xsl:for-each> </ul> <ul class="mensLinks" style="width:45%; float:left;"> <xsl:for-each select="root/minimapproducts/item"> <xsl:if test="position() &gt; $split"> <li> <a> <xsl:attribute name="href"> <xsl:value-of select="/root/gendermix/cat" />/<xsl:value-of select="@url"/> </xsl:attribute> <xsl:attribute name="title"> <xsl:value-of select="@name"/> </xsl:attribute> <xsl:value-of select="@name"/> </a> </li> </xsl:if> </xsl:for-each> </ul>
