[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

Subject: Re: Sorting list of XML data into multiple columns
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 29 Mar 2001 10:16:10 +0100
select case 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() &lt; 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() &lt; 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() &lt; 3]" />
         <xsl:for-each select=".|$others">
            <td>
               <xsl:call-template name="checkboxcurrency" />
            </td>
         </xsl:for-each>
         <xsl:if test="count($others) &lt; 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.