How does attribute inheritance work in DITA?

Attribute inheritance in DITA refers to the way attributes are passed down or propagated from higher-level elements to lower-level elements within the document hierarchy. This mechanism ensures consistency and simplifies attribute management by allowing values defined at higher levels to apply to lower-level elements unless overridden.

DITA Attribute Inheritance

Higher-Level Elements: In DITA, documents are structured hierarchically, with higher-level elements containing or referencing lower-level elements. For example, a DITA map contains references to DITA topics.

Attribute Assignment: Attributes can be assigned at different levels within the hierarchy. Attributes can be defined at various levels, including the DITA map level, the topic level, and even within individual elements like paragraphs or sections.

Propagation: When an attribute is assigned to a higher-level element, it propagates down to lower-level elements, including the content within those elements. This means that the attribute value is inherited by default unless explicitly overridden at a lower level.

Override: At any point in the hierarchy, you can override the inherited attribute value by assigning a different value to the same attribute. This local assignment takes precedence over the inherited value.

Inheritance Chain: If an attribute is assigned at multiple levels in the hierarchy, the value of the nearest ancestor takes precedence. DITA follows a chain of inheritance to determine the final attribute value for a specific element.

Example:

A DITA map for a user manual contains references to two DITA topics: “Chapter 1” and “Chapter 2.” The @audience attribute is used to define the target audience for these chapters.


        <map>
            <topicref href="chapter1.dita" audience="beginner" />
            <topicref href="chapter2.dita" />
        </map>
    

In this example:

  • The @audience attribute is assigned to “chapter1.dita” with the value “beginner.”
  • The @audience attribute is not explicitly assigned to “chapter2.dita,” so it inherits the value “beginner” from its parent in the hierarchy.

After content revision, “chapter2.dita” becomes intended for an “intermediate” audience, you can override the inherited value:


        <map>
            <topicref href="chapter1.dita" audience="beginner" />
            <topicref href="chapter2.dita" audience="intermediate" />
        </map>
    

Now, “chapter2.dita” has its own @audience attribute value of “intermediate,” which overrides the inherited value from the map level.