XML technologies / DocBook / Block elements / Tables / Comparing table models
(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)
The differences between table models are partly historical and partly practical. Compared with CALS, the Exchange table model includes several simplifications that make it easier to use in some applications.
The CALS table model
This table model exists in both DocBook 4 and DocBook 5. A CALS table must contain at least one element tgroup, which can contain the following elements:
thead,tfootHeader and footer, both optional
tbodyTable body containing the actual entries
A basic table therefore looks as follows:
Example: Structure of a table
<table>
<title>...</title>
<tgroup cols="X">
<thead><!-- ... --></thead>
<tfoot><!-- ... --></tfoot>
<tbody><!-- ... --></tbody>
</tgroup>
<!-- evtl. weitere tgroup -->
</table>Line 1: As expected, a table begins with table.
Line 2: Table title
Line 3: Group containing the header, footer, and entries. The table’s column count must be specified in the attribute cols. DocBook 5 allows only positive integers greater than zero.
Lines 4 and 5: The optional header and footer are specified at the start of tgroup (see Defining headers and footers in CALS tables).
Line 6: The actual table entries are inserted here using the element tbody.
Line 8: A table can have several tgroup elements, each with different column counts, headers, and footers.
In the element tbody insert table rows using row. Mark the columns using entry. A single table entry with two columns therefore looks as follows:
<row>
<entry>1. Spalteneintrag</entry>
<entry>2. Spalteneintrag</entry>
</row> Note: Number of entry elements
Each table entry must contain exactly as many entry elements as specified by the cols attribute in tgroup. A different number of entry elements causes misalignment in the table.
This rule does not apply when merging cells or columns.
The OASIS Exchange XML table model
This table model exists only in DocBook 4. Compared with CALS, the Exchange table model has several simplifications:
The element
tfootexists only in CALS.Within
thead, only the CALS table model allows the elementcolspec.In CALS, several columns can be spanned using the element
spanspec; the Exchange table model does not provide for this.Nested tables are possible only in the CALS table model, using the element
entrytbl.Some attributes exist only in CALS, such as
tgroupstyleintgrouporrotateinentry.
Since these differences are minor, no example is provided. To change the table model for your XML document, see the explanation in “DocBook table models”.
The (X)HTML table model
The (X)HTML table model exists in both DocBook 4 and DocBook 5. It was added to better support users familiar with (X)HTML. It allows two notations, the second closely resembling CALS. “Simple” tables use the elements tr (table row), th (header cell), and td (table data):
Example: (X)HTML table with tr, th and td
<table>
<caption>...</caption>
<tr>
<th>Kopf 1</th>
<th>Kopf 2</th>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</table>The code above is useful for simple data or for reusing existing (X)HTML tables unchanged. If you have a lot of data and want the header or footer repeated after a break, you can mark it explicitly. This then resembles the CALS model:
Example: (X)HTML table with a header
<table>
<caption>Titel</caption>
<thead>
<tr>
<th>...</th>
<th>...</th>
</tr>
</thead>
<!-- tfoot, falls gewünscht -->
<tbody>
<tr>
<td>...</td>
<td>...</td>
</tr>
<!-- Weitere tr-Elemente -->
</tbody>
</table>Be sure to keep the order thead, tfoot, tbody. The header and footer may each occur only once per table. In contrast, tbody may occur any number of times, but at least once.
For more information about (X)HTML tables, see HTML and XHTML elements by function: tables.
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de