Can conditions be set at both element and topic levels in DITA?
Conditions in DITA can be set at both the element and topic levels, offering flexibility in controlling the inclusion or exclusion of content based on specific criteria. This enables fine-grained control over conditional processing.
Element-Level Conditions:
Element-level conditions involve applying conditions to specific elements within a DITA topic.
These conditions allow for control of the inclusion or exclusion of individual elements, such as paragraphs, images, or other content.
Element-level conditions can be useful for scenarios which require the content creator to specify conditions for small sections of content within a topic.
Topic-Level Conditions:
Topic-level conditions are defined for the entire DITA topic.
These conditions control the inclusion or exclusion of the entire topic based on specific criteria.
Topic-level conditions are typically set in the topic’s metadata or within the topicref in a DITA map.
They are suitable for situations where entire topics may need to be included or excluded in the output.
Example:
A DITA documentation project for a software product includes a series of topics related to various features. There’s a need to apply conditions both at the element and topic levels based on audience segments (beginners and advanced users).
Element-Level Conditions:
<p>Introduction to the software.</p>
<p conkeyref="audience=beginner">This feature is for beginners.</p>
<p conkeyref="audience=advanced">This advanced feature is for experienced users.</p>
In this example:
- The introductory paragraph is not conditioned and is included for all audiences.
- Element-level conditions are set for the feature descriptions based on the audience key, allowing specific content to be included for beginners and advanced users.
Topic-Level Conditions:
<map>
<topicmeta>
<keywords>
<keyword keyname="audience" keyscope="local">
<keyword keyref="beginner" conaction="exclude" />
<keyword keyref="advanced" conaction="exclude" />
</keyword>
</keywords>
</topicmeta>
</map>
In this example:
- Topic-level conditions are defined in the DITA map’s metadata using keywords and their conaction attributes.
- Topics with conaction=”exclude” will be excluded for the specified audience condition.
Topic-Level conditions can also be applied using the @conref
attribute in the DITA map:
<topicref href="beginner_topic.dita" conkeyref="audience=beginner" />
<topicref href="advanced_topic.dita" conkeyref="audience=advanced" />
Here, the @conkeyref
attribute on topicref elements is used to conditionally include or exclude entire topics based on the specified audience condition.