Subject: Re: [xsl] Organizing list of items in HTML table From: "Paul Tyson" <paul@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 27 Sep 2001 13:32:25 -0700 |
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])"> <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@xxxxxxxxxxxxxxxxxxxxxx> To: "xsl-list" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Thursday, September 27, 2001 8:35 AM Subject: [xsl] Organizing list of items in HTML table > > >From: "Ron Chibnik" <ron@xxxxxxxxxxx> > >To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx> > >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@xxxxxxxxxxxxxxxx > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Organizing list of items in H, Mulberry Technologie | Thread | Re: [xsl] Organizing list of items , Paul Tyson |
Re: [xsl] Position X Sort-> Please , Wendell Piez | Date | Re: [xsl] Position X Sort-> Please , Paulo Henrique S. Be |
Month |