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

laying out list of nodes in 2 table columns

Subject: laying out list of nodes in 2 table columns
From: "Wong Chin Shin" <publicbbs@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Nov 2004 02:24:41 +0800
xsl table columns
Hi,

I've got an XML file that looks like the following:

<Services>
	<ServiceItem>
		<ServiceName>Item 1</ServiceName>
	</ServiceItem>
	<ServiceItem>
		<ServiceName>Item 2</ServiceName>
	</ServiceItem>
	<ServiceItem>
		<ServiceName>Item 3</ServiceName>
	</ServiceItem>
	<ServiceItem>
		<ServiceName>Item 4</ServiceName>
	</ServiceItem>
</Services>

Basically I want to lay them out into a table of 2 columns which looks like
this:

<table>
	<tr><td>Item 1</td><td>Item 2</td></tr>
	<tr><td>Item 3</td><td>Item 4</td></tr>
</table>

So far, I've managed to come up with the XSL rules for the left column, but
I just can't seem to find the right node for the right column:

<xsl:template match="Services">
	<table border="1" cellpadding="0" cellspacing="0" width="90%"
align="center">
		<tbody>
			<xsl:for-each select="ServiceItem[(position()-1) mod
2 = 0]">
				<xsl:apply-templates select="." />
			</xsl:for-each>
		</tbody>
	</table>
</xsl:template>
<xsl:template match="ServiceItem[(position()-1) mod 2 = 0]">
	<tr>
		<td width="50%" valign="top">
			<p><xsl:value-of select="ServiceName" /></p>
		</td>
		<td>
			<xsl:for-each
select="parent/following-sibling::node()[position() &lt; 2]">
				<xsl:value-of select="ServiceName" />
			</xsl:for-each>
		</td>
	</tr>
</xsl:template>

I'm now still trying to find the right rule for the 2nd column... Can
anybody help? I'm basically a newbie, and trying to do things right... I
guess the ugly workaround is to force 2 blocks on data into one XML node n
then do a for-each but that would really defeat the purpose...

Thanks!
Wong

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.