Re: Problem with XSL transform of XML file to dynamic HTML table with fixed columns

Discussion in 'XML' started by Marrow, Jul 2, 2003.

  1. Marrow

    Marrow Guest

    Hi,

    This is a bit of an FAQ, try something like...

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="html" indent="yes"/>
    <xsl:param name="no-cols" select="3"/>
    <xsl:template match="images">
    <html>
    <body>
    <table border="1">
    <xsl:for-each select="image[position() mod $no-cols = 1 or $no-cols
    = 1]">
    <tr>
    <xsl:for-each select=". | following-sibling::image[position()
    &lt; $no-cols]">
    <td>
    <a href="" onclick="openImageWindow('{@url}')">
    <img src="{@url}" alt="_{@url}" class="?"/>
    </a>
    </td>
    </xsl:for-each>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Or with the filtering for orientation too...

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="html" indent="yes"/>
    <xsl:param name="no-cols" select="3"/>
    <xsl:param name="orient" select="'vertical'"/>
    <xsl:template match="images">
    <html>
    <body>
    <table border="1">
    <xsl:for-each select="image[@orientation = $orient][position() mod
    $no-cols = 1 or $no-cols = 1]">
    <tr>
    <xsl:for-each select=". | following-sibling::image[@orientation
    = $orient][position() &lt; $no-cols]">
    <td>
    <a href="" onclick="openImageWindow('{@url}')">
    <img src="{@url}" alt="_{@url}" class="?"/>
    </a>
    </td>
    </xsl:for-each>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator

    "__grumpoxl" <> wrote in message
    news:...
    > I'm having some problems creating an html table from an xml document
    > with xsl.
    >
    > Here is the important piece of my xml input document.
    >
    > <images>
    > <image url="stl/images/stl_02.jpg" orientation="vertical"/>
    > <image url="stl/images/stl_03.jpg" orientation="vertical"/>
    > <image url="stl/images/stl_05.jpg" orientation="vertical"/>
    > <image url="stl/images/stl_08.jpg" orientation="horizontal"/>
    > <image url="stl/images/stl_12.jpg" orientation="vertical"/>
    > <image url="stl/images/stl_arch_01.jpg" orientation="vertical"/>
    > <image url="stl/images/stl_arch_02.jpg" orientation="vertical"/>
    > </images>
    >
    > What I want is to be able to show all images in a table, but to
    > recognize when the number of columns hit a maximum, and to create a
    > new row. The fact that I'm dealing with images is irrelevant, it has
    > more to do with the details of xsl.
    >
    > What I tried was to loop through all images, and do a calculation of
    > the current node location() mod maxColumns each time, to see when I
    > had to end the current row and start a new one. But what I ended up
    > with was an xsl:text node which was trying to write /tr tr, which is
    > not well formed xml.
    >
    > <tr>
    > <xsl:for-each select="images/image[@orientation='horizontal']">
    >
    > <td>
    >
    > <xsl:variable name="imageUrl">
    > <xsl:value-of select="@url"/>
    > </xsl:variable>
    >
    > <a href="" onclick="openImageWindow('{$imageUrl}')">
    > <img src="{$imageUrl}" alt="_{$imageUrl}"
    > class="{$imageClass}"/>
    > </a>
    >
    > </td>
    >
    > <xsl:if test="position() mod 3 = 0">
    > <xsl:text disable-output-escaping="no">
    >
    > <!-- This won't work, not well-formed -->
    > </tr><tr>
    >
    >
    > </xsl:text>
    > </xsl:if>
    >
    > </xsl:for-each>
    > </tr>
    >
    > Has anyone encountered a similar problem, and if so, can you provide
    > some help or suggestions?
    Marrow, Jul 2, 2003
    #1
    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. KathyB
    Replies:
    0
    Views:
    1,004
    KathyB
    Jun 25, 2003
  2. Anthony Harkness-Gripe

    Dataset to XSL Transform not displaying HTML--only XML

    Anthony Harkness-Gripe, Aug 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    980
    itnrant
    Jul 8, 2008
  3. telescient telescient via .NET 247

    How to transform xml variable to xsl file using asp.net using vb.net

    telescient telescient via .NET 247, Apr 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    836
    Matt Berther
    Apr 4, 2005
  4. Johannes Koch
    Replies:
    0
    Views:
    840
    Johannes Koch
    Jul 2, 2003
  5. enggr
    Replies:
    0
    Views:
    1,622
    enggr
    Jun 30, 2010
Loading...

Share This Page