Subject: Re: [xsl] Organizing list of items in HTML table From: "Paul Tyson" <paul@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 27 Sep 2001 14:01:16 -0700 |
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@xxxxxxxxxxxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Organizing list of items , Paul Tyson | Thread | [xsl] Template Matching, Jeffrey Langdon |
Re: [xsl] Position X Sort-> Please , Paulo Henrique S. Be | Date | RE: [xsl] Position X Sort-> Please , Chris Bayes |
Month |