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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | /* set all cells to a consistent state*/ table: { cells[all].bottomedgestrokeweight : 0pt; cells[all].fillcolor : white; cells[all].filltint: 100; } /* first column */ column:first-of-type { fillcolor : red; filltint: 10; } /* Nested selector, for each cell in header rows */ header cell: { fillcolor : red; filltint: 50; } /* cells that contain the field 'job_title' */ cell#job_title { fillcolor : green; } /* last cell in each body row */ body cell:last-of-type { fillcolor : blue; filltint: 40; } /* match the cells content parent records 'city' field matching 'Seattle' */ body cell[city='Seattle'] { fillcolor : blue; filltint: 20; } /* Header rows*/ header: { bottomedgestrokeweight: 1pt; } /* last body row*/ body:last-of-type { bottomedgestrokeweight: 1pt; } |
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:
1 2 3 | body cell#surname[surname='Lee'] { cells[all].fillcolor : yellow; } |
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
| Selector | Name | Description | Example |
|---|---|---|---|
* | Universal | Selects all elements | * |
element | Type / Element | Selects all elements of a given type | cell |
#id | ID | Selects 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 B | Descendant | Selects elements inside another element | body cell |
A > B | Child | Selects direct children only | body > cell |
[attr=value] | Attribute equals | Selects elements with an exact attribute value. On cell and row object the attributes names are derived from the parent record present. | [city="Seattle"] |
:pseudo-class | Pseudo-class | Selects elements in a specific state | body cell:last-of-type |
A, B | Selector list | Selects multiple elements | header, 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:
1 2 3 4 5 6 | /* Set all the body row cells to white, then the last 2 cells to red and blue */ body { cells[all].fillcolor : white; cells[last].fillcolor : red; cells[last-1].fillcolor : blue; } |
DOM Navigation
Most DOM object can refer to their parent object or children. For example:
1 2 3 4 5 6 7 8 9 | /* Apply a column fill to the column the cell is in */ body cell { parentColumn.fillColor : red; } /* Apply a fill to all cells in the last column */ table { columns[last].cells[all].fillcolor : blue; } |
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:
1 2 3 4 5 6 7 8 9 | column { textleftinset : 0pt; } column#forename { /* Matches the field 'forename' */ textleftinset : 10pt; } column#age { /* Matches the field 'age' */ cells[all].fillcolor : red; } |
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:
| Operator | Meaning | Example |
|---|---|---|
| = | 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.
1 2 3 4 5 6 | /* cell containg a record with a field 'city' matching 'Seattle' */ body cell[city='Seattle'] { fillcolor : blue; filltint: 20; words[all].appliedFont : Minion Pro^tItalic; } |
Example Output
Using a simple set of data, the stylesheet above produces the following output:
