This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Organizing list of items in HTML table
Ooops, you need an additional test before filling the last row, in case the
number of columns divides the number of images evenly. See correction
below.
--Paul
----- Original Message -----
From: "Paul Tyson" <paul@precisiondocuments.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Thursday, September 27, 2001 1:32 PM
Subject: Re: [xsl] 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> </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 > count(image)"/>
> <xsl:otherwise>
> <xsl:text> </xsl:text>
> <tr>
> <xsl:apply-templates
> select="image[position() >= $n and
> position() < $n + $numCols]"/>
> <xsl:if test="not(image[position() >= $n + $numCols])">
*** Correction: above line should be:
<xsl:if test="not(image[position() >= $n + $numCols]) and
count(image) mod $numCols">
*** end of correction.
> <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
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list