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

Subject: Re: [xsl] FO/XSL:Setting up columns in a for-each loop
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 1 Nov 2001 18:26:40 +0000
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