[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: FO/XSL:Setting up columns in a for-each loop

Subject: Re: FO/XSL:Setting up columns in a for-each loop
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 31 Oct 2001 18:19:58 +0000
xsl fo four column table
Hi Rachael,

> Thanks so much for the response. Do you happen to know where I can
> find any FO examples of this type of logic. I am trying this example
> and others, but I keep getting errors. I think my placements are
> wrong.

Here's an example. The source is as follows:

<list>
  <item>item1</item>
  <item>item2</item>
  ...
  <item>item3</item>
</list>

And you want to create a four-column table. The list equates to an
fo:table:

<xsl:template match="list">
  <fo:table>
    <fo:table-body>
      ...
    </fo:table-body>
  </fo:table>
</xsl:template>

Now, you want to generate a row for every fourth item in the list. You
can get every fourth item by seeing if its position mod 4 is equal to
1 with:

  position() mod 4 = 1

You can iterate over every fourth item with an xsl:for-each (or you
can apply templates to them) as follows:

<xsl:template match="list">
  <fo:table>
    <fo:table-body>
      <xsl:for-each select="item[position() mod 4 = 1]">
        <fo:table-row>
          ...
        </fo:table-row>
      </xsl:for-each>
    </fo:table-body>
  </fo:table>
</xsl:template>

Now you need to create a cell for the current item and its three
following siblings. You can get the current item with . and its three
following siblings with:

  following-sibling::item[position() &lt; 4]

And you can iterate over these with xsl:for-each again (or
xsl:apply-templates if you prefer):

<xsl:template match="list">
  <fo:table>
    <fo:table-body>
      <xsl:for-each select="item[position() mod 4 = 1]">
        <fo:table-row>
          <xsl:for-each
              select=". | following-sibling::item[position() &lt; 4]">
            <fo:table-cell>
              <xsl:value-of select="." />
            </fo:table-cell>
          </xsl:for-each>
        </fo:table-row>
      </xsl:for-each>
    </fo:table-body>
  </fo:table>
</xsl:template>

If that example doesn't help, you could always send the part of the
stylesheet that's causing problems and we can see if we can spot where
it should be changed.

I hope that helps anyway,

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.