xsl-list
[Top] [All Lists]

RE: Newbie question: Incrementing the position in the tree midstream

2004-04-12 13:36:32
-----Original Message-----
From: Durston, Andrew (AGRE)

<snip />
test-plan/object/cell N
test-plan/object/cell N+1
test-plan/object/cell N+2
test-plan/object/cell N+3

I can search to find cell N. I'd like to be able to print cell N,
cell N+1, cell N+2 ... all at once and then when XSL goes back
to searching (via a For) through the tree, it skips N+1, N+2 etc.
(basically does a table row and then skips to the beginning of
the next row). Without entering another XML attribute into our DB
to indicate beginning and end of rows... How do I increment
the position, moving from object/cell N to object/cell N+1 midstream?


Hi,

Based on the above source tree, how are the rows in the result separated? By
being in different objects? Or does it depend solely on the index of the
cell (fixed number of cells in one row)?

(I think your problem is one of groupîng, so the obvious starting point
would be
http://www.jenitennison.com/xslt/grouping)

As an example, for positional grouping, 5 cells per row, you can do:

<table>
<xsl:for-each select="test-plan/object/cell[
               (position() mod 5)=1]">
  <tr>
  <xsl:for-each select=". | following-sibling::cell[
                  position() &lt;= 4]">
    <td><xsl:value-of select="." /></td>
  </xsl:for-each>
  </tr>
</xsl:for-each>
</table>


Hope this helps!

Cheers,

Andreas