This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: FO/XSL:Setting up columns in a for-each loop
- To: Rachael Blank <blankrr at mars-systems dot com>
- Subject: Re: [xsl] FO/XSL:Setting up columns in a for-each loop
- From: Jeni Tennison <jeni at jenitennison dot com>
- Date: Thu, 1 Nov 2001 18:26:40 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <3BD71C21.E46ED72A@mars-systems.com><87ofmv62b6.fsf@sophia.inria.fr> <3BE0299F.CD7D6015@mars-systems.com><17917550155.20011031181958@jenitennison.com><3BE184B4.E398F9FF@mars-systems.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Rachael,
> Thanks so much for your help. But I still can't get my <xsl:for-each
> select="header | following-sibling::header[position() < 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() < 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