[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: Thu, 1 Nov 2001 18:26:40 +0000
xsl process every odd element
Hi Rachael,

> Thanks so much for your help. But I still can't get my <xsl:for-each
> select="header | following-sibling::header[position() &lt; 2]"> to
> display anything, even without FO. We are using the SAXON parser.

You show in your XML that each header element is a child of a report
element, and each report element has only one child header element.
The path:

  header

gets the header child of the current node (which I guess is the report
element). The path:

  following-sibling::header[position() &lt; 2]

gets the header elements that follow the current report element and
that its siblings (have the same parent). There are never any such
header elements, because every header element is nested underneath a
report element.

So, look at the problem again. You want to create a table from a
section element (using HTML as it's less verbose than FO):

<xsl:template match="section">
  <table>
    ...
  </table>
</xsl:template>

Within the table, each row contains the result of transforming two
report elements, so you want to apply templates to every odd report
element to create the row:

<xsl:template match="section">
  <table>
    <xsl:for-each select="report[position() mod 2 = 1]">
      <tr>
        ...
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>

Then you want to process that report and its immediately following
sibling, and for each create one cell that contains the result of
processing the header and another cell that contains the result of
processing the comment:

<xsl:template match="section">
  <table>
    <xsl:for-each select="report[position() mod 2 = 1]">
      <tr>
        <xsl:for-each select=". | following-sibling::report[1]">
          <td><xsl:apply-templates select="header" /></td>
          <td><xsl:apply-templates select="comment" /></td>
        </xsl:for-each>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>

I hope that fixes it,

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.