Re: Variable number of table columns

"G. Ken Holman" <[email protected]>
Newsgroups gmane.text.xml.xsl.general
Message-ID <[email protected]>
At 2002-11-14 04:51 -0500, Eklund Anders wrote:
>I have an .xml-file with tables. The problem is that I don't know the 
>number of columns in each table.
>Then I don't know how many <fo:table-column> I need to have a proportional 
>table where all tables have the same width.

You will have to go to the effort of anticipating your column needs, 
usually by practically duplicating the algorithm for creating your columns 
but only in order to obtain a count.

Your example data was easy, in that each row of each table has the same 
number of columns, so my answer to your question looks almost too easy 
below.  But, you win if that is truly the shape of your data.  The problem 
comes when you have an arbitrary number of columns in an arbitrary number 
of rows and you want to find the largest number of columns of all the 
rows.  This is left as an exercise to the reader!

I hope this helps.

........................ Ken

   <fo:table>

      <xsl:for-each select="row[1]/column">
        <fo:table-column column-width="50pt"/>
      </xsl:for-each>

        <fo:table-body>
          <xsl:for-each select="row">
            <fo:table-row>
              <xsl:for-each select="column">
                <fo:table-cell>
                  <fo:block><xsl:value-of select="."/></fo:block>
                </fo:table-cell>
              </xsl:for-each>
            </fo:table-row>
          </xsl:for-each>
       </fo:table-body>
    </fo:table>


--
Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO:
-                             North America:  Feb 3 - Feb 7,2003

G. Ken Holman               mailto:[email protected]
Crane Softwrights Ltd.        http://www.CraneSoftwrights.com/f/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                     Definitive XSLT and XPath
ISBN 0-13-140374-5                             Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1             Practical Formatting Using XSL-FO
Next conference training:                    2002-12-08,03-03,06
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.