Table with 2 columns

Here should go questions about transforming XML with XSLT and FOP.
Furious
Posts: 4
Joined: Mon Jan 05, 2009 11:08 pm

Table with 2 columns

Post by Furious »

Hi,

I am quite new to XSL and have maybe a simple problem, but i am not sure what the best solution might be.

imagine a xml file:

<root>
<number> 1 </number>
<number> 2 </number>
<number> 3 </number>
<number> 4 </number>
<number> 5 </number>
</root>

I would like to put this numbers into a table with 2 columns.

imagine a table:
column1--column2
1------------------ 2
3------------------ 4
5---------

The point is, that i do not know how many numbers/table-cells there are. There might be 5 or 99.

So, is it possible to count the <number> nodes and automaticly put the 1. 3. 5. etc nodes in the first/left column and 2. 4. 6. etc in the second/right column?

I am trying to figure the code out, but if someone could write it here, that would be really awesome!
Furious
Posts: 4
Joined: Mon Jan 05, 2009 11:08 pm

Re: Table with 2 columns

Post by Furious »

<fo:table-body background-color="green">
<xsl:for-each
select="numb[position() < $tableLength + 1]">
<xsl:variable name="pos" select="position()"/>
<fo:table-row>

<fo:table-cell border="2">
<fo:block>
<xsl:choose>
<xsl:when test="../numb[$pos mod 2 > 0]">
<xsl:value-of select="../numb[$pos]"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>

</fo:block>
</fo:table-cell>

<fo:table-cell>
<fo:block>
<xsl:choose>
<xsl:when
test="../numb[($pos + 1) mod 2 < 1]">
<xsl:value-of select="../numb[$pos + 1]"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</fo:block>
</fo:table-cell>

</fo:table-row>
</xsl:for-each>
Post Reply