By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,784 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,784 IT Pros & Developers. It's quick & easy.

XSL: creating a <UL> within a <TABLE>

P: n/a
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.

I thought this would work but I get this error:
"End tag 'xsl:if' does not match the start tag 'ul'."

Any thoughts?
<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>

Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Can you post a sample input and desired output?

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

"bearclaws" <go**********@bencannon.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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.

I thought this would work but I get this error:
"End tag 'xsl:if' does not match the start tag 'ul'."

Any thoughts?
<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>

Jul 20 '05 #2

P: n/a
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() &lt; 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
Jul 20 '05 #3

P: n/a
Joris -
Your solution worked perfectly!

I figured it had something to do with the separated tags but couldn't
find any solid examples online.

Many thanks,
BC

Jul 20 '05 #4

P: n/a
Joris -

Your solution worked perfectly!

I figured it had something to do with the separated tags but couldn't
find any solid examples online.

Many thanks,
BC

Jul 20 '05 #5

P: n/a
Joris -

Your solution worked perfectly!

I figured it had something to do with the separated tags but couldn't
find any solid examples online.

Many thanks,
BC

Jul 20 '05 #6

P: n/a
On 18 Feb 2005 11:39:42 -0800, "bearclaws"
<go**********@bencannon.com> wrote:
I am looping through a list of categories and want to display the list
horizontally (instead of vertically).


Then use CSS to control the presentation of the <ul>, don't mess with
tables.

Jul 20 '05 #7

P: n/a
Tempore 17:44:14, die Saturday 19 February 2005 AD, hinc in foro {comp.text.xml} scripsit Andy Dingley <di*****@codesmiths.com>:
I am looping through a list of categories and want to display the list
horizontally (instead of vertically).


Then use CSS to control the presentation of the <ul>, don't mess with
tables.

I completely agree

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #8

P: n/a
Good thinking. Using CSS works too (and spares me the table logic
mess).

Here are two articles I found helpful for creating multiple column
lists using CSS:

http://www.communitymx.com/content/a...F87&print=true

http://pikasoftware.net/docs/index.p...e_Column_Lists

Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.