Re: [xsl] math get maximum and subtract 1

Subject: Re: [xsl] math get maximum and subtract 1
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 25 Jul 2002 09:50:04 +0100
Hi Sascha,

> i tried this, but FOP doesn't seem to like the starts-row attribute-
> "not implemented yet" :-(
> what am i gonna do now? 

Now you're going to use a grouping method. You need to group your
DESCRIPTION_ITEM elements based on their position and your knowledge
of the number of rows in the table which (if you remember) you can get
by looking at the row attribute of the last DESCRIPTION_ITEM element:

  <xsl:variable name="nrows"
                select="DESCRIPTION_ITEM[last()]/@row + 1" />

Now, in your sample there were 5 rows, and the DESCRIPTION_ITEM
elements were sorted based on their column and then their row, so the
first 5 DESCRIPTION_ITEM elements were for the first column, the next
5 for the second column and so on.

You need to do some processing once per row to create the rows; the
easiest way to do that is to iterate over the first cells in each row
-- the DESCRIPTION_ITEMs whose col attribute has the value 0:

  <xsl:for-each select="DESCRIPTION_ITEM[@col = 0]">

Now, if you're on row 0 then you need to populate that row with the
DESCRIPTION_ITEM elements positioned 1, 6, 11 and so on in your list.
If you're on row 1 then you need the DESCRIPTION_ITEM elements
positioned 2, 7, 12 and so on. See the pattern? You need to look at
their position, mod the number of rows in the table ($nrows), and see
if it's the same as the number of row you're currently creating (the
value of the row attribute on the current DESCRIPTION_ITEM) at plus

  <xsl:for-each select="DESCRIPTION_ITEM[@col = 0]">
      <xsl:for-each select="../DESCRIPTION_ITEM
                              [position() mod $nrows =
                               current()/@row + 1]">

Note that this only works because your DESCRIPTION_ITEMs are sorted by
column and then by row. If they're sorted in some other way, or aren't
actually sorted at all, then we need to try another method.



Jeni Tennison

 XSL-List info and archive:

Current Thread