[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Sorting list of XML data into multiple columns
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|