### 38.3 Adding attributes with PI markers

An attribute PI marker includes the name of the attribute as a suffix to the predefined PI marker type name. The content of the marker becomes the value of the attribute for the applicable element tag:

    <elementname attributetype="content">

For example, for HTML output, a Rowbgcolor PI marker with content yellow, placed just before a DITA <entry> tag, would add the attribute bgcolor with value yellow to the HTML <tr> tag for the current table row:

    <?dthtm Rowbgcolor="yellow" ?>

results in:

    <tr bgcolor="yellow">

Nonconforming attribute markers

A few attribute PI markers do not conform exactly to this naming and usage convention; for example, WAI support PI markers CellGroup and CellSpan. See §35.2.4 Assigning table-cell attribute values with PI markers. Another nonconforming attribute marker is Meta Type. For HTML output, this marker causes a <meta> tag to be added to the <head> element; Type becomes the value of the name attribute, and the content of the marker becomes the value of the content attribute.

Concatenated attribute markers

Although the text of a DITA PI marker is not limited in length, you can concatenate all PI markers for the same attribute that are inserted before the next item to which they apply. You can just add more PI markers of the same type, and continue the content. For example:

    <?dthtm tablesummary="This table shows the properties" ?>
    <?dthtm tablesummary=" you can use for thingamabobs." ?>

Also:

- Inserting another PI marker of a different type between two PI markers for the same attribute does not prevent concatenation, even if the middle PI marker is a different attribute PI marker for the same element.
- If you want the content of two concatenated attribute PI markers to be separated by a space in the attribute value, you must provide the space, either at the end of content in the first PI marker or at the beginning of content in the second PI marker.

Extra attributes

Using PI markers to add attributes can result in extra attributes for a given tag. Browsers ignore extra attributes, but validators would not be pleased; see §22.14 Passing W3C validation tests. (Of course validators would not be pleased with most of what is on the Web, so that might be of little consequence.)

Duplicate markers

If multiple attribute PI markers with identical names but different content apply to the same element, DITA2Go uses the content of the last PI marker encountered as the value of the attribute.

For HTML or XML output, DITA2Go treats any PI marker that has a name that begins with Cell, Char, Graph, Link, Meta, Para, Row, or Table as an attribute PI marker. For HTML (for example), DITA2Go inserts the attribute="value" pair specified by each of the attribute marker types as follows:

Cell Attr | In the <td> or <th> tag for the enclosing table cell.
Char Attr | In the tag for the current or next inline element.
Graph Attr | In the next <img> tag.
Link Attr | In the next link (<a href=...>) tag.
Meta Type | In a <meta> tag; produces a new element, <meta name="Type" content="content">, in the <head> element.
Para Attr | In the tag for the current block element.
Row Attr | In the <tr> tag for the current table row; best practice is to place the marker in the first cell in the row.
Table Attr | In the <table> tag, in the enclosing table; if not positioned in a table, applies to the next table in the same flow.

Table 38-2 lists the elements to which each attribute PI marker can apply for each output type.

Table 38-2 Elements to which attribute PI markers apply, by output type

Marker | Output type
HTML/XHTML | Generic XML | DITA XML | DocBook XML
Cell Attr | <td>, <th> | <td>, <th> | <entry>, <stentry>, <choption>, <chdesc>, <proptype>, <propvalue>, <propdesc> | <td>, <th>
Char Attr | inline elements | inline elements | inline elements | inline elements
Graph Attr | <img> | <img> | <image> | <imagedata>
Link Attr | <a> ( (does not apply to Help pop-ups, secondary window jumps, or footnote cross references) | <a> (applies to the AtagElement setting; do not use for name; overridden by XMLLinkAttrs) | <xref> (can add to or replace standard href, type, format, and scope attributes) | <xref>, <ulink>
Meta Type | <meta> | <meta> |  |
Para Attr | block elements | block elements | block elements | block elements
Row Attr | <tr> | <tr> | <row>, <strow>, <chrow>, <property> | <tr>, <row>
Table Attr | <table> | <table> | <table>, <simpletable>, <choicetable>, <properties> | <table>

Previous Topic: 38.2 Understanding effects of PI markers

Next Topic: 38.4 Assigning properties to PI marker types

Parent Topic: 38. Working with processing instructions

Sibling Topics:

38.1 Understanding DITA2Go PI markers

38.2 Understanding effects of PI markers

38.4 Assigning properties to PI marker types

38.5 Inserting code with PI markers