This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Organizing list of items in HTML table


These few templates appear to do what you want.  Modify the 'image' template
to get what you want in each table cell.  Adjust the 'numCols' parameter for
different number of columns.

  <xsl:output method="html"/>
  <xsl:param name="numCols" select="3"/>

  <xsl:template match="imageList">
    <table>
      <xsl:call-template name="make-rows"/>
    </table>
  </xsl:template>

  <xsl:template match="image">
    <xsl:text>&#10;</xsl:text>
    <td>
      <img>
        <xsl:attribute name="src">
          <xsl:value-of select="./imageName"/>
        </xsl:attribute>
      </img>
    </td>
  </xsl:template>

  <xsl:template name="make-rows">
    <xsl:param name="n" select="1"/>
    <xsl:choose>
      <xsl:when test="$n &gt; count(image)"/>
      <xsl:otherwise>
        <xsl:text>&#10;</xsl:text>
        <tr>
          <xsl:apply-templates
            select="image[position() &gt;= $n and
                    position() &lt; $n + $numCols]"/>
          <xsl:if test="not(image[position() &gt;= $n + $numCols])">
            <xsl:call-template name="fill-row">
              <xsl:with-param name="num-empty"
                select="$numCols - count(image) mod $numCols"/>
            </xsl:call-template>
          </xsl:if>
        </tr>
        <xsl:call-template name="make-rows">
          <xsl:with-param name="n" select="$n + $numCols"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="fill-row">
    <xsl:param name="num-empty"/>
    <xsl:choose>
      <xsl:when test="$num-empty = 0"/>
      <xsl:otherwise>
        <td></td>
        <xsl:call-template name="fill-row">
          <xsl:with-param name="num-empty" select="$num-empty - 1"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Good luck,
Paul Tyson
paul at precisiondocuments dot com

----- Original Message -----
From: "Mulberry Technologies List Owner"
<xsl-list-owner@lists.mulberrytech.com>
To: "xsl-list" <xsl-list@lists.mulberrytech.com>
Sent: Thursday, September 27, 2001 8:35 AM
Subject: [xsl] Organizing list of items in HTML table


>
> >From: "Ron Chibnik" <ron@chibnik.com>
> >To: <XSL-List@lists.mulberrytech.com>
> >Subject: Organizing list of items in HTML table
> >Date: Thu, 27 Sep 2001 09:21:19 -0400
> >
> >I'm trying to organize a list of images into a table. I've looked at the
FAQ
> >for "Tables" and have almost gotten item 8 (XSL Table Styling) to work
but I
> >get the error
> >   "xsl:with-param is not allowed in this position in the stylesheet!"
> >I'm using Xalan dated Feb 2, 2001 (don't know exactly which version.)
> >
> >Perhaps someone has some code handy that will provide a simple
> >solution. My XML is similar to:
> >
> >   <imageList>
> >    <image>
> >    <imageName>image1.jpg</imageName>
> >    ... other image stuff like captions, etc. ...
> >    </image>
> >    <image>
> >    <imageName>image1.jpg</imageName>
> >    </image>
> >    ...
> >    <image>
> >    <imageName>image7.jpg</imageName>
> >    </image>
> >   </imageList>
> >
> >And I would like to produce a table something like:
> >   <table>
> >    <tr>
> >    <td>image1</td>
> >    <td>image2</td>
> >    <td>image3</td>
> >    </tr>
> >    <tr>
> >    <td>image4</td>
> >    <td>image5</td>
> >    <td>image6</td>
> >    </tr>
> >    <tr>
> >    <td>image7</td>
> >    </tr>
> >   </table>
> >
> >Ideally, I'd like to be able to specify the # of columns, either by
editing
> >the style sheet, or through some parameter in the XML file. But my
biggest
> >problem is getting the table columns to work right. The Example I've been
> >using (from the FAQ) duplicates some, and omits one or more images
> >(depending on how many images in imageList).
> >
> >Thanks in advance for any advice you can provide
> >Regards
> >Ron
>
>
> --
> ======================================================================
> B. Tommie Usdin                        mailto:btusdin@mulberrytech.com
> Mulberry Technologies, Inc.                http://www.mulberrytech.com
> 17 West Jefferson Street                           Phone: 301/315-9631
> Suite 207                                    Direct Line: 301/315-9634
> Rockville, MD  20850                                 Fax: 301/315-8285
> ----------------------------------------------------------------------
>   Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]