Applying CSS Style Stylesheets to Tables

Use the Table->Table Options->Stylesheet dialog to apply DOM properties to the table using CSS style selectors. Stylesheets are processed at the end of table population.

Data for the following example can he downloaded here

Selectors

Selectors define when the specified properties should be applied and use regular CSS style syntax. The properties defined by the selector are any existing ย writable DOM property. Nested properties within objects can be denoted by separating each part of the property with a period.

Selectors can be used to target specific elements of a table. The example below targets all cells in body rows where the cell contains the surname field and content of the surnameย field is Lee:

Selectors match to InDesign DOM objects as follows:

table – table object
column – column object
body : row object
header: row object
footer: row object
cell : cell object

SelectorNameDescriptionExample
*UniversalSelects all elements*
elementType / ElementSelects all elements of a given typecell
#idIDSelects the element with a specific ID. An ID on a column object isย the name of the field in the column. On cell objects the id is the field name in the cell. Field names should always be in lowercase.#header
A BDescendantSelects elements inside another elementbody cell
A > BChildSelects direct children onlybody > cell
[attr=value]Attribute equalsSelects elements with an exact attribute value. On cell and row object the attributes names are derived from the parent record present.[city="Seattle"]
:pseudo-classPseudo-classSelects elements in a specific statebody cell:last-of-type
A, BSelector listSelects multiple elementsheader, body

Consult the Adobe InDesign DOM documentation for a list of all properties available.

Using Collections

This mechanism support Collections. In the example above, the cells[all] collection is used to set properties on all cells in the table. Collections can reference objects by index, or using a selector keywords such as all, first, last. In the case of first and last, relative positions can be specified. The following example sets the fill color for the last 2 cells in each body row:

DOM Navigation

Most DOM object can refer to their parent object or children. For example:

Matching by ID

CSS support selection by ID. This uses a syntax like cell#job_title.ย In stylesheets the ID is the field name used in the first found in a row, column or cell, so cell#job_title matches cells that contain a field named “job_title”. IDs should be lowercase to match, for example:

Matching by Attribute

CSS also supports using attributes. In stylesheets, the attributes are derived from the fields in a record, so body cell[city=’Seattle’] matches all body cells that contain a field whose parent record contains the field city containing ‘Seattle‘. The folowing operators are supported:

OperatorMeaningExample
=Exact match[city="Seattle"]
~=Contains word (space-separated)[class~="active"]
|=Exact match or starts with value-[lang|="en"]
^=Starts with[href^="https"]
$=Ends with[src$=".png"]
*=Contains substring[title*="north"]

class and style fields

If the data used to populate the table includes a field named class, its value will be treated as a CSS selector and applied from the stylesheet. Similarly, if there is a field named style containing a list of CSS properties, those properties will also be applied.

Note: This feature only works when the stylesheet contains some content.

Delimited DOM Properties

Some DOM properties accept strings that are delimited by a Tab character. In these cases, the ^t meta sequence should be used. For example, the appliedFont property accepts a font name and an optional face name. To apply Minion Pro, Italic, the syntax would be as shown below. In the following example, a property named city is matched. These properties are derived by examining the cellโ€™s content and the looking at the fields of the record to which it belongs. In the case of tabular fields, the field name is the column ID.

Example Output

Using a simple set of data, the stylesheet above produces the following output: