#### 33.6.7 Selectively modifying table text with macros: an example

Suppose the following:

- Some columns in your tables have text that you want bold in HTML, even though in DITA the text is not differentiated with an inline element.
- The columns in question all have column headings that include the word “Fields”.
- The paragraph format for table body cells is CellBody, and the format for column headings is CellHeading.

To achieve selective bolding, you can use macros to assign different class attributes to paragraph format CellBody, based on the content of each column heading.

Use macro variables to identify table columns

Create two macro variables to hold column numbers; for example, $$ColNum and $$FieldColNum. $$ColNum counts the columns in a table, and $$FieldColNum holds the column number of any column whose heading contains the word “Fields”.

If you are not using table macros for any other purpose, you can use a wildcard to specify the following macros for all tables:

    [TableStartMacros]
    ; Reset $$FieldColNum for each table:
    *=<$$FieldColNum = 0>

    [TableRowStartMacros]
    ; Reset $$ColNum for each table row:
    *=<$$ColNum = 0>

    [TableCellStartMacros]
    ; Increment $$ColNum for each table column:
    *=<$$ColNum++>

See also:

§33.2.2 Using wildcards to specify table sets

§33.6.1 Invoking macros around tables

§37.3 Using macro variables

Assign coding options to table-cell formats

Turn off the HTML paragraph tag that DITA2Go would otherwise automatically assign to CellBody, and specify macro code for both CellBody and CellHeading:

    [HTMLParaStyles]
    ; CellBody formatting will be replaced by macro code:
    CellBody=NoPara CodeStart CodeEnd
    ; CellHeading will hold column-heading content to be checked,
    ;  and also provide the code for checking:
    CellHeading=CodeStore CodeAfter

    [ParaStyleCodeStart]
    ; Assign a macro to CellBody, so the code can exceed one line:
    CellBody=<$SelectClass>

    [ParaStyleCodeEnd]
    ; Provide a closing tag for the class attribute:
    CellBody=</p>

    [ParaStyleCodeAfter]
    ; Use the CodeStore property assigned to CellHeading to
    ;  capture the content of the current CellHeading paragraph,
    ;  and also assign a macro, so the code can exceed one line:
    CellHeading=<$$CellHeading><$CheckColHead>

See also:

§30.2.4 Stripping paragraph properties

§37.3.2 Assigning values to macro variables

§37.9.3 Surrounding or replacing text with code or macros

§37.3.5.2 Inserting code with the CodeStore property

Check for columns that need bolding

Use a conditional expression to check the content of each CellHeading paragraph:

    [CheckColHead]
    ; Use string operator "contains" to check the content;
    ;  if the text sought is present, flag the column:
    <$_if ($$CellHeading contains "Fields")>
      <$$FieldColNum = $$ColNum>
      <$_endif>

Select a class attribute based on the column flag

To select a class attribute for CellBody, compare $$ColNum and $$FieldColNum in a conditional expression:

    [SelectClass]
    <p class="<$_if ($$FieldColNum == $$ColNum)>CellBodyBold
      <$_else>CellBody
      <$_endif>">

See also:

§37.6.4 Using control structures in expressions

§37.6.5 Specifying substrings in expressions

Previous Topic: 33.6.6 Capturing table row and column counts with variables

Next Topic: 33.7 Converting tables to paragraphs

Parent Topic: 33.6 Using macros to control table properties

Sibling Topics:

33.6.1 Invoking macros around tables

33.6.2 Adding space before tables

33.6.3 Adjusting space after tables

33.6.4 Turning processing on and off around selected tables

33.6.5 Specifying row-group, row, and cell attributes with macros

33.6.6 Capturing table row and column counts with variables

Table of Contents • Index