[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Sorting list of XML data into multiple columns

Subject: Sorting list of XML data into multiple columns
From: "Tim Watts" <timw@xxxxxxx>
Date: Thu, 29 Mar 2001 11:32:17 +1000
xml sort list
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.