What is conditional processing in DITA and why is it used?

Conditional processing operates by using conditional attributes, conditions and keys, and conditional processing instructions.

Conditional Attributes:

Conditional processing is achieved through special attributes in DITA elements, notably the @conkeyref and @conref attributes.

@conkeyref allows referencing keys that define conditions in a DITA map.

@conref allows including content from another topic, applying conditions defined by key references.

Conditions and Keys:

Conditions are defined using keys in a DITA map. These keys can represent various criteria, such as the output format, the target audience, or the product version.

Each key can have multiple values, each associated with specific conditions. For example, a key named “audience” may have values like “beginner” and “advanced.”

Conditional Processing Instructions:

Conditional processing instructions are added to DITA elements to specify which content should be included or excluded based on the conditions.

Instructions can be positive (include this content when the condition is met) or negative (exclude this content when the condition is met).

Example:

A user manual needs to include different content for beginner and advanced users. The DITA source might look like this:


  <!-- Defining keys and conditions in the DITA map -->
  <map>
    <keydef keys="audience" keyscope="local">
      <topicmeta>
        <keywords>
          <keyword keyname="beginner">Beginner</keyword>
          <keyword keyname="advanced">Advanced</keyword>
        </keywords>
      </topicmeta>
    </keydef>
  </map>

  <!-- In a DITA topic -->
  <p conref="beginner_topic.dita" conkeyref="audience=beginner">This content is for beginners.</p>
  <p conref="advanced_topic.dita" conkeyref="audience=advanced">This content is for advanced users.</p>
  

In this example:

  • A key named “audience” is defined in the DITA map with two values: “beginner” and “advanced.”
  • Conditional processing instructions are added to the <p> elements, referencing the keys. When the output is generated, only the content relevant to the specified audience condition is included.