[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Sorting list of XML data into multiple columns
Subject: Re: [xsl] Sorting list of XML data into multiple columns From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Thu, 29 Mar 2001 10:16:10 +0100 |
Hi Tim, The usual way of doing the grouping-by-position that you're describing is to process only to the first in each group (i.e. in your case those option elements whose position() mod 3 = 1), to create the grouping element (i.e. the tr) within that template, and then process that node and to the rest in that group (i.e. the next two option elements) to get the item content. So, in your case, you process only the option elements whose position() mod 3 is 1: <xsl:for-each select="document('../currency.xml')/select/option [position() mod 3 = 1]"> ... </xsl:for-each> Create the grouping element (the tr): <xsl:for-each select="document('../currency.xml')/select/option [position() mod 3 = 1]"> <tr> ... </tr> </xsl:for-each> And then process that option element and its two following siblings: <xsl:for-each select="document('../currency.xml')/select/option [position() mod 3 = 1]"> <tr> <xsl:for-each select=".| following-sibling::option[position() < 3]"> ... </xsl:for-each> </tr> </xsl:for-each> And create whatever you need to create for them them: <xsl:for-each select="document('../currency.xml')/select/option [position() mod 3 = 1]"> <tr> <xsl:for-each select=".| following-sibling::option[position() < 3]"> <td> <xsl:call-template name="checkboxcurrency" /> </td> </xsl:for-each> </tr> </xsl:for-each> This arranges the option elements across the page rather than down it in columns, and gives them in whatever order they originally came in, which may or may not be what you want. If you need to add empty cells, then you need to check whether the option element actually has any following siblings, and if not then create empty cells for them: <xsl:for-each select="document('../currency.xml')/select/option [position() mod 3 = 1]"> <tr> <xsl:variable name="others" select="following-sibling::option[position() < 3]" /> <xsl:for-each select=".|$others"> <td> <xsl:call-template name="checkboxcurrency" /> </td> </xsl:for-each> <xsl:if test="count($others) < 2"> <td></td> <xsl:if test="not($others)"> <td></td> </xsl:if> </xsl:if> </tr> </xsl:for-each> I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Sorting list of XML data , Tim Watts | Thread | [xsl] XALAN - obtaining the -XSL st, Robert Nicholson |
RE: [xsl] Passing Parameters or ?, Michael Kay | Date | Re: [xsl] Problem in define Node-se, Yang |
Month |