Subject:looping to generate 2 columnar table ! Author:hardik mehta Date:23 Nov 2005 07:51 AM
Hi all,
First greetings to all. I am a new member of this forum and also relatively new to XSLT.
I am trying to generate an xsl:fo file using xml document and xslt.
now, I requre 2 columnar table looping through node in xml.
To be precise it looks like following..
xml file:
<some-node>
<node-of-interest>
<sub-node1> val1 </sub-node1>
</node-of-interest>
<node-of-interest>
<sub-node1> val2 </sub-node1>
</node-of-interest>
<node-of-interest>
<sub-node1> val3 </sub-node1>
</node-of-interest> ........
</some-nodes>
and i wanted to select row according to the fn:position() is even or the final node ....
xsl logic (not written in std syntax to save time and space )
<table>
<xsl:for-each select="some-nodes/node-of-interest" >
<if test="position() odd">
<row>
</if>
<cell>
<xsl:value-of select="sub-node1" />
</cel>
<cell>
<xsl:value-of select="sub-node1" />
</cel>
<if test="position() even or last()">
</row>
</if>
</xsl:for-each>
</table>
this implementation fails because of incomplte <row> element !!!
is there any other way to loop through ... may be with the step of 2 nodes ??
Subject:looping to generate 2 columnar table ! Author:(Deleted User) Date:23 Nov 2005 08:30 AM
Hardik,
I would try something like this:
<xsl:for-each>
<xsl:if (odd)>
<row>
- generate cell for position()
- generate cell for position()+1 if it exists
</row>
</xsl:if>
Subject:looping to generate 2 columnar table ! Author:(Deleted User) Date:23 Nov 2005 09:09 AM
Hardik,
First, I think FO has facilities for automatically generating 2 column output. I suggest you investigate that.
But, in your example, you can do something like this:
<xsl:variable name="nodes" select="node-of-interest[suvalue = test]"/>
<xsl:for-each select="$nodes">
<xsl:if odd>
<row>
- generate cell for position()
- generate cell for position()+1 if it exists
</row>
</xsl:if>
</xsl:for-each>