Subject: [xsl] Building tables with XSLT From: "Dan Henke" <danh@xxxxxxxxxxxxxx> Date: Tue, 10 Sep 2002 16:43:30 +1000 |
Hi, I've included some sample XML and a cutdown XSLT stylesheet that I'm using to generate a table 4 columns wide and as many rows long as needed with an image in each cell. The stylesheet also pads out the last few cells if there isnt a multiple of 4 images. The part I'm stuck on is taking this working example and making it able to build a table any number of columns wide dictated by a parameter passed to the template. Another point I'm stuck on is that the real life XML file might have 100 images in it and I am hoping to be able to generate the table from a subset of those images. For example, given a long list of <IMAGE> nodes as below I might want to create a table which is 5 columns wide and contains all of the images from position 20 to position 35. I'm pushing my XSLT ability already so any help in working this problem out would be greatly appreciated. -Dan Here is a fragment from my XML source: <IMGAGES> <IMAGE HEIGHT="100" WIDTH="120">image01.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image02.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image03.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image04.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image05.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image06.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image07.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image08.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image09.gif</IMAGE> <IMAGE HEIGHT="100" WIDTH="120">image10.gif</IMAGE> </IMAGES> And a cutdown version of the XSLT file I'm using is like this: <xsl:template match="/"> <xsl:call-template name="displayRow"> <xsl:with-param name="pos" select="1"/> </xsl:call-template> </xsl:template> <xsl:template name="displayRow"> <xsl:param name="pos"/> <tr> <xsl:call-template name="displayCell"> <xsl:with-param name="pos" select="$pos"/> </xsl:call-template> <xsl:call-template name="displayCell"> <xsl:with-param name="pos" select="$pos + 1"/> </xsl:call-template> <xsl:call-template name="displayCell"> <xsl:with-param name="pos" select="$pos + 2"/> </xsl:call-template> <xsl:call-template name="displayCell"> <xsl:with-param name="pos" select="$pos + 3"/> </xsl:call-template> </tr> <xsl:if test="IMAGES/IMAGE[$pos + 4]"> <xsl:call-template name="displayRow"> <xsl:with-param name="pos" select="$pos + 4"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="displayCell"> <xsl:param name="pos"/> <xsl:variable name="CELL" select="IMAGES/IMAGE[$pos]"/> <xsl:choose> <xsl:when test="$CELL"> <td align="center" valign="middle"> <img src="{$CELL}" height="{$CELL/@HEIGHT}" width="{$CELL/@WIDTH}" border="0"/> </td> </xsl:when> <xsl:otherwise> <td> </td> </xsl:otherwise> </xsl:choose> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] insert default node if it, Jarno . Elovirta | Thread | Re: [xsl] Building tables with XSLT, Carsten Klein |
RE: [xsl] insert default node if it, Jarno . Elovirta | Date | RE: [xsl] XSL transform escape ques, Michael Kay |
Month |