Background color

You can insert a background color for individual table cells by using a processing instruction, or whole rows with a customization. Currently the row customization only works for HTML output.

Cell background color

You can use a dbhtml or dbfo processing instruction to set the background color for an individual table cell. The processing instructions can appear anywhere within the entry element. Here is an example.

<table>
<title>Background color</title>
<tgroup cols="4">
<colspec colnum="1" colname="col1" colwidth="1*"/>
<colspec colnum="2" colname="col2" colwidth="1*"/>
<colspec colnum="3" colname="col3" colwidth="1*"/>
<colspec colnum="4" colname="col4" colwidth="1*"/>
<thead>
<row>
<entry>Column 1 heading
<?dbhtml bgcolor="#EEEEEE" ?><?dbfo bgcolor="#EEEEEE" ?></entry>
<entry>Column 2 heading</entry>
<entry>Column 3 heading
<?dbhtml bgcolor="#EEEEEE" ?><?dbfo bgcolor="#EEEEEE" ?></entry>
<entry>Column 4 heading</entry>
</row>
</thead>
<tbody>
<row>
<entry>Entry 1.1</entry>
<entry>Entry 2.1</entry>
<entry>Entry 3.1</entry>
<entry>Entry 4.1</entry>
</row>
...

This example puts a light gray background behind two of the table headings. You need to use both processing instructions if you want the background color in both HTML and print.

Row background color

You can also use the bgcolor processing instructions to turns on background color for a whole row. To associate the PI with the row, it has to be inside the row element but not inside any entry element. So place the PI between the start tag of the row element and the start tag of the first entry element.

<row>
<?dbhtml bgcolor="#EEEEEE" ?><?dbfo bgcolor="#EEEEEE" ?>
<entry>Column 1 heading</entry>
<entry>Column 2 heading</entry>
<entry>Column 3 heading</entry>
<entry>Column 4 heading</entry>
</row>

You can still override the row color for specific cells by adding a PI in each individual entry element within the row.

What if you want a table that put a background color on alternating rows? You could put the same bgcolor processing instruction on each row, but that can become tedious.

The alternative is to create a stylesheet customization that allows you to apply styles to rows based on either a role attribute or a row count. The HTML stylesheet provides an empty template named tr.attributes that can be customized for such purposes. Here is an example that puts a class="oddrow" attribute on every other row if the table's tabstyle attribute is set to striped. Then you supply a CSS stylesheet that applies a background color to the TR rows with a class="oddrow" attribute.

<xsl:template name="tr.attributes">
  <xsl:param name="row" select="."/>
  <xsl:param name="rownum" select="0"/>

  <xsl:if test="ancestor::table/@tabstyle = 'striped'>
    <xsl:if test="$rownum mod 2 = 0">
      <xsl:attribute name="class">oddrow</xsl:attribute>
    </xsl:if>
  </xsl:if>

</xsl:template>

This template could also respond to other tabstyle attribute values to produce different styles. For example, if you turn on the background color for all rows, then effectively the whole table has a background color.

To get alternating color rows for print output, you can customize the table.cell.properties template. See the section “table.cell.properties template” for examples of such customizations.