Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL: creating a <UL> within a <TABLE>

Reply
Thread Tools

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

 
 
bearclaws
Guest
Posts: n/a
 
      02-18-2005
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>

 
Reply With Quote
 
 
 
 
Stan Kitsis [MSFT]
Guest
Posts: n/a
 
      02-18-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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>
>



 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      02-18-2005
Tempore 20:39:42, die Friday 18 February 2005 AD, hinc in foro {comp.text.xml} scripsit bearclaws <(E-Mail Removed)>:

> 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
 
Reply With Quote
 
bearclaws
Guest
Posts: n/a
 
      02-18-2005
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

 
Reply With Quote
 
bearclaws
Guest
Posts: n/a
 
      02-18-2005
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

 
Reply With Quote
 
bearclaws
Guest
Posts: n/a
 
      02-18-2005
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

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      02-19-2005
On 18 Feb 2005 11:39:42 -0800, "bearclaws"
<(E-Mail Removed)> 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.

 
Reply With Quote
 
Joris Gillis
Guest
Posts: n/a
 
      02-19-2005
Tempore 17:44:14, die Saturday 19 February 2005 AD, hinc in foro {comp.text.xml} scripsit Andy Dingley <(E-Mail Removed)>:

>> 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
 
Reply With Quote
 
bearclaws
Guest
Posts: n/a
 
      03-02-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
GetElementbyID question - within MasterPage/contentpage - within tables Elmo Watson ASP .Net 1 05-08-2007 05:12 PM
How do I include a server tag within a javascript parameter which is itself within a HTML element event? mark4asp ASP .Net 2 11-07-2006 06:23 AM
Referring to a textbox within a web control within an aspx KatB ASP .Net 0 04-22-2005 07:14 PM
search within a search within a search - looking for better way...my script times out Abby Lee ASP General 5 08-02-2004 04:01 PM



Advertisments