Example

To illustrate how to generate a custom table in practice, we will return to the example at the beginning of this section. Consider an invoice that consists of a number of items as follows:

<invoice>
  <item>
    <code>SL6500A</code>
    <quantity>20</quantity>
    <unit-price>14.50</unit-price>
    <total-price>290.00</total-price>
  </item>
  ...
</invoice>

This requires a table of 4 columns, with the first column somewhat wider to accommodate the item code. So the Pre content for invoice calls the following commands:

<table-start/>
<table-column width="2*"/>
<table-column/>
<table-column/>
<table-column/>
<InvoiceHeader/>
<table-body/>

The second last command is a custom marker that we will use to specify a standard table header. So the Pre content for %InvoiceHeader will be:

<table-head/>
<table-cell align="center">Item Code</table-cell>
<table-cell align="center">Quantity</table-cell>
<table-cell align="center">Unit Price</table-cell>
<table-cell align="center">Total Price</table-cell>

Since each item represents a table row, either the Pre content or Post content customisation for item should call <table-nextrow/>. While the table will overflow fill if all four values are always present, in general it's better to call <table-nextrow/> explicitly as this ensures the correct row structure even if a value is missing.

The mappings for the value elements (code, quantity, unit-price and total-price) are identical. Each mapping scans and suppresses the element content, then declares the following Pre content customisation:

<table-cell align="right"><content/></table-cell>

to produce a right-aligned cell. If the underlying table model is CALS, you can add an explicit colnum="N" to force the values into a designated column.

Finally, the Post content for invoice defines <table-emit/> to complete and display the table as follows: