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

Discussion in 'XML' started by bearclaws, Feb 18, 2005.

  1. bearclaws

    bearclaws Guest

    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>
     
    bearclaws, Feb 18, 2005
    #1
    1. Advertising

  2. Re: creating a <UL> within a <TABLE>

    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" <> wrote in message
    news:...
    >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>
    >
     
    Stan Kitsis [MSFT], Feb 18, 2005
    #2
    1. Advertising

  3. bearclaws

    Joris Gillis Guest

    Tempore 20:39:42, die Friday 18 February 2005 AD, hinc in foro {comp.text.xml} scripsit bearclaws <>:

    > 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-view.cgi?userid=38041)
    "Quot capita, tot sententiae" - Terentius , Phormio 454
     
    Joris Gillis, Feb 18, 2005
    #3
  4. bearclaws

    bearclaws Guest

    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
     
    bearclaws, Feb 18, 2005
    #4
  5. bearclaws

    bearclaws Guest

    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
     
    bearclaws, Feb 18, 2005
    #5
  6. bearclaws

    bearclaws Guest

    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
     
    bearclaws, Feb 18, 2005
    #6
  7. bearclaws

    Andy Dingley Guest

    On 18 Feb 2005 11:39:42 -0800, "bearclaws"
    <> 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.
     
    Andy Dingley, Feb 19, 2005
    #7
  8. bearclaws

    Joris Gillis Guest

    Tempore 17:44:14, die Saturday 19 February 2005 AD, hinc in foro {comp.text.xml} scripsit Andy Dingley <>:

    >> 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-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
     
    Joris Gillis, Feb 19, 2005
    #8
  9. bearclaws

    bearclaws Guest

    bearclaws, Mar 2, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Selden McCabe

    Table within a Table - spacing

    Selden McCabe, Jan 14, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    351
    MWells
    Jan 15, 2005
  2. Kevin Flood
    Replies:
    0
    Views:
    1,040
    Kevin Flood
    Sep 8, 2004
  3. Replies:
    1
    Views:
    3,653
    A. Bolmarcich
    May 27, 2005
  4. Targa

    Drag & Drop table within table

    Targa, Oct 7, 2004, in forum: ASP General
    Replies:
    1
    Views:
    212
    Mark Schupp
    Oct 7, 2004
  5. Camet
    Replies:
    0
    Views:
    128
    Camet
    Jul 6, 2006
Loading...

Share This Page