This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Sorting list of XML data into multiple columns
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Sorting list of XML data into multiple columns
- From: "Tim Watts" <timw at 3d3 dot com>
- Date: Thu, 29 Mar 2001 11:32:17 +1000
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi,
I have come across a problem which I am sure will have been solved before.
In the XML I have a list of countries which I would like displayed in
columns in html in the form wirth check boxes...
<table>
<tr>
<td>country A</td>
<td>country B</td>
<td>country C</td>
</tr>
<tr>
<td>country D</td>
<td>country E</td>
<td>country F</td>
</tr>
....
</table>
or (but more difficultly) in the form
<table>
<tr>
<td>country A</td>
<td>country D</td>
<td>country G</td>
</tr>
<tr>
<td>country B</td>
<td>country E</td>
<td>country H</td>
</tr>
<tr>
<td>country C</td>
<td>country F</td>
<td>country I</td>
</tr>
</table>
(with the list running down the page)
The data is already sorted in the XML to save complexity there,
How can I go about this? Tests of position are not going to work with the
countires to detemine when the <tr> closes and the next one begins, because
the templates need to complete the <tr>
I've tried something like this...
<xsl:template name="paymentsystemcurrency">
<xsl:for-each select="document('../currency.xml')/select/option">
<xsl:choose>
<xsl:when test="position() mod 3 = 1">
<![CDATA[ <tr> ]]>
<td colspan="2">
<xsl:choose>
<xsl:when test="option[@iso]/selected=yes">
<input type="checkbox" name="payment/currency[@iso]/selected"
value="yes" checked="checked" />
</xsl:when>
<xsl:otherwise>
<input type="checkbox" name="payment/currency[@iso]/selected"
value="yes" />
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="@iso"/>
</td>
</xsl:when>
<xsl:when test="position() mod 3 = 2">
<td colspan="2">
<xsl:choose>
<xsl:when test="option[@iso]/selected=yes">
<input type="checkbox" name="payment/currency[@iso]/selected"
value="yes" checked="checked" />
</xsl:when>
<xsl:otherwise>
<input type="checkbox" name="payment/currency[@iso]/selected"
value="yes" />
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="@iso"/>
</td>
</xsl:when>
<xsl:otherwise>
<td colspan="2">
<xsl:choose>
<xsl:when test="option[@iso]/selected=yes">
<input type="checkbox" name="payment/currency[@iso]/selected"
value="yes" checked="checked" />
</xsl:when>
<xsl:otherwise>
<input type="checkbox" name="payment/currency[@iso]/selected"
value="yes" />
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="@iso"/>
</td>
<![CDATA[ </tr> ]]>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
But this method is full of problems and I shouldn't need to use CDATA stuff,
and this doesn't account for a number of countires/currencies which isn't
divisable by three.
Thanks for all help and advice
Tim
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list