10. Tables

XSL-FO supports an own table structure which meets the typographical requirements of a typesetting and break system. This table structure is neither identical with the traditional CALS table structure nor with the HTML table structure. But it is very suitable in order to take both table models as initial point for the typographical implementation. The XSL-FO table concept is especially easy to use for the table setting of so-called semantic table data such as they are exported from database applications to the typesetting.

For the setting of tables nine elements and numerous attributes are available. The following graphic shows the structure which arises out of this.

Element structure of a table

Element structure of a table

The elements are:

  • <fo:table> is the central (the top) and obligatory element for generating a table. It has an optional column definition (<fo:table-column>), one or several optional header and footer table characters, (<fo:table-header> and <fo:table-footer>), and the obligatory table body (<fo:table-body>).

  • <fo:table-header> generates the header of the table which is automatically repeated if a page break occurs.

  • <fo:table-body> contains the tabular content of the table which consists of rows (<fo:table-row>) which, in turn, consist of cells (<fo:table-cell>).

  • <fo:table-footer> generates the footer of a table which is automatically repeated if a page break occurs.

  • <fo:table-column> allows the pre-specification of various characteristics for the columns of the table.

  • <fo:table-and-caption>: If the table has a headline or a caption, this element is the top and obligatory table element.

  • <fo:table-caption> incorporates the headline or caption of a table which has <fo:table-and-caption> as top element.

  • <fo:table-row> determines the content and the characteristics of the table rows.

  • <fo:table-cell> determines the content and the characteristics of the table cells.

 

The attributes of the table elements

Since the elements can be typographically treated with many attributes, here only the table-specific attributes are explained in more detail and the attributes being already known are only briefly presented. Attributes being irrelevant in practice are not discussed.

<fo:table> (table attributes) 

  • background attribute, border attribute, padding attribute, margin attribute, space attribute, id, break-after, break-before, keep-with-next, keep-with-previous, keep-together

  • height, width

  • border-collapse defines the model to be used for the neighbouring cell borders. When using the collapse value, the neighbouring borders collapse and generate a joint cell separation. When using separate, each cell generates its own border. A space can be defined for the neighbouring border. These areas outside the borders may be filled with the background defined for the table.

  • border-separation defines the space between two neighbouring borders which may be filled with the background defined for the table.

  • table-layout determines an algorithm for the layout of the table cells, rows and columns. The dafault value is auto. This value makes – according to HTML tables – the width of a column dependent on the cell contents in this column. With the fixed value the table layout is solely determined by the width of the table and the columns, borders and spaces between the borders contained in the table.

  • table-omit-footer-at-break determines whether the footer of a table (<fo:table-footer>) shall be repeated on the next pages if a break over the given page occurs. The default value is false, so the footer is repeated. Only if the value true is specified, the footer is not repeated.

  • table-omit-header-at-break is the repetition attribute for the header <fo:table-header>. The same rules as for the footer apply.

 

<fo:table-column> (attribues for the column definition)

  • background attributes, border attributes, padding attributes

  • column-number (number of the column). A valid value is a number, for example 1 for the 1st column. This number is used to assign the column specifications to the cells which have the same value for column-number.

  • column-width (width of the column). Valid values are any supported absolute measures or percentages (table width is 100%).

  • number-columns-repeated (number of the columns for which this specification shall apply). Valid values are integers, for example 2.

  • number-columns-spanned (number of the columns which shall be spanned). Valid values are integers, for example 2.

 

<fo:table-body>, <fo:table-header>, <fo:table-footer> (attributes for the table regions)

  • background attributes, border attributes, padding attributes, id (assignment of an unique identification)

 

<fo:table-row> (table row attributes)

  • background attributes, border attributes, padding attributes, id, break-after, break-before, keep-with-next, keep-with-previous, keep-together

  • height (row height)

 

<fo:table-cell> (table cell attributes)

  • background attributes, border attributes, padding attributes, id.

  • height (cell height) and width (cell width)

  • display-align (vertical alignment of the cell content). The default value is auto and effects that the cell content is treated as if the before value was defined. When using the common wrtiting direction, the before vaue effects the alignment at the top cell margin, center effects a central alignment and after the alignment at the bottom cell margin.

  • empty-cells (borders around blank cells). The default value is show, so blank cells have a border like the cells with contents. An alternative value is hide which represses the borders. If all cells of a table row have the attribute value hide, the whole table row is repressed when displayed.

  • ends-row (end of a table row). The default value is false, so the given cell ends no table row. With the alternative value true the given cell ends the table row. This applies only when the cells are not within <fo:table-row>.

  • starts-row (start of a new table row). The same as for ends-row applies.

  • column-number (number of the column). A connection is established to the specification of the appropriate <fo:table-column>.

  • number-columns-spanned (number of the columns to be spanned). The default value is 1, so the cell fills one column. According to the integer attribute value, columns are spanned in the writing direction. For example, the cell spans three columns with an attribute value of 3.

  • number-rows-spanned (number of the table rows to be spanned). The same as for number-columns-spanned applies.

Please note: The horizontal alignment of the cell content is not specified itself as an attribute of the cell, but as an attribute of the blocks in the cell!

For the start a simpe table example:

<fo:block>
<fo:table>
   <fo:table-body>
      <fo:table-row>
         <fo:table-cell>
            <fo:block> Erste Zelle</fo:block>
                       <!-- en: First Cell -->
         </fo:table-cell>
         <fo:table-cell>
            <fo:block> Zweite Zelle</fo:block>
                       <!-- Second Cell -->
         </fo:table-cell>
         <fo:table-cell>
            <fo:block> Dritte Zelle</fo:block>
                       <!-- Third Cell -->
         </fo:table-cell>
      </fo:table-row>
   </fo:table-body>
</fo:table>                         
</fo:block>

This table is the basic form of a table. But some characteristics are missing. Size specifications for the table, its rows or cells are not indicated and the table cells have no borders. The next example shall be more complex and contain these characteristics.

<fo:block>
<fo:table width="110mm" border-style="ridge" border-width="5pt">       (1)                        
   <fo:table-body>                                                     (2)
      <fo:table-row>                                                   (3)
         <fo:table-cell width="40mm" border-style="solid" border-width="1pt"> (4)
            <fo:block> 1. Zelle</fo:block>                         
         </fo:table-cell>                         
         <fo:table-cell width="40mm" border-style="solid" border-width="1pt"> (4)
            <fo:block> 2. Zelle</fo:block>
         </fo:table-cell>
         <fo:table-cell width="30mm" border-style="solid" border-width="1pt"> (4)
            <fo:block> 3. Zelle</fo:block>                         
         </fo:table-cell>                         
      </fo:table-row>                                                 (3)
      <fo:table-row>
         <fo:table-cell border-style="solid" border-width="1pt">      (5)
            <fo:block> 1. Zelle</fo:block>
         </fo:table-cell>
         <fo:table-cell border-style="solid" border-width="1pt">      (5)
            <fo:block> 2. Zelle</fo:block>
         </fo:table-cell>
         <fo:table-cell border-style="solid" border-width="1pt">      (5)
            <fo:block> 3. Zelle</fo:block>
         </fo:table-cell>
      </fo:table-row>
   </fo:table-body>
</fo:table>
</fo:block>

(1) The <fo:table> element contains the content of a table. The width attribute determines the width of the table. The border-style attribute defines the outer border of the table. The outer border differs from the borders of the cells.

(2) <fo:table-body> is the container for the content of the table which has no header or footer.

(3) <fo:table-row> defines a row of a table. Here, also various attributes are allowed which have not been mentioned for purposes of simplification.

(4) <fo:table-cell> defines a cell. In this example the first two cells have a width of 40mm, the third has a width of 30mm. The cells have a complete border (border-style="solid" border-width="1pt").

(5) The cells in the second row have in contrast to the ones of the first row no width specifications. Therefore, the width indications of the first row are automatically adopted.

Formatter view

Formatter view - table cells

The following example is a far more complex one which shows the most common table characteristics:

<fo:block>
<fo:table width="110mm" border-style="outset" border-width="1pt">     (1)                      
   <fo:table-column column-number="1" column-width="25%" 
    border-style="solid" border-width="1pt"/>                         (2)                       
   <fo:table-column column-number="2" column-width="25%" border-style="solid" border-width="1pt"/>
   <fo:table-column column-number="3" column-width="25%" border-style="solid" border-width="1pt"/>
   <fo:table-column column-number="4" column-width="25%" border-style="solid" border-width="1pt"/>
   <fo:table-header background-color="red">                           (3)
      <fo:table-row>                         
         <fo:table-cell number-columns-spanned="4">                   (4)
            <fo:block>Kopfzeile</fo:block> 
                      <!-- en: Header -->
         </fo:table-cell>
      </fo:table-row>
   </fo:table-header>
   <fo:table-footer background-color="red">                           (3)                        
      <fo:table-row>
         <fo:table-cell number-columns-spanned="4">                   (4)
            <fo:block>Fusszeile</fo:block>
                      <!-- Footer -->
         </fo:table-cell>                         
      </fo:table-row>
   </fo:table-footer>                         
   <fo:table-body>
      <fo:table-row border-style="double" border-width="1pt">                         
         <fo:table-cell column-number="1">                            (5)
            <fo:block> 1. Zelle</fo:block>
                      <!-- 1. Cell -->
         </fo:table-cell>
         <fo:table-cell column-number="2">                            (5)
            <fo:block> 2. Zelle</fo:block>
         </fo:table-cell>                         
         <fo:table-cell column-number="3" number-columns-spanned="2"> (5)
            <fo:block> 3. Zelle</fo:block>                         
         </fo:table-cell>
      </fo:table-row>
      <fo:table-row border-style="double" border-width="1pt">
         <fo:table-cell column-number="1" number-columns-spanned="2"> (5)
            <fo:block> 1. Zelle</fo:block>                         
         </fo:table-cell>
         <fo:table-cell column-number="3">                            (5)
            <fo:block> 2. Zelle</fo:block>                         
         </fo:table-cell>
         <fo:table-cell column-number="4">                            (5)
            <fo:block> 3. Zelle</fo:block>                         
         </fo:table-cell>                         
      </fo:table-row>
   </fo:table-body>
</fo:table>
</fo:block>

(1) The width attribute determines the overall width of the table.

(2) The columns are defined with the <fo:table-column> element. A number with the column-number attribute and a width widh the column-width attribute is assigned to each column. The width of a column is indicated in percent of the overall width of the table (110mm).

(3) The table has a header highlighted by colour which is specified with the <fo:table-header> element and a footer of the same colour which is specified with the <fo:table-footer> element. The background-color attribute expects as a value a predefined colour value, like red in this example, or a RGB three colour value.

(4) In the footer and header the table cell contains the number-columns-spanned attribute with the value "4". So the cell spans over all four columns.

(5) The table cells in the body (<fo:table-body>) are assigned to the predefined columns with the help of the column-number attribute.

Formatter view

Formatter view

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo@dpunkt.de