Edit online

DITA 1.3 Key Scopes - Next Generation of Reuse

Read time: 4 minute(s)

In this blog post I'm going to give you a small example of how key scopes can benefit simple cases of reuse which could not be done previously.

Let's say you have a simple DITA task in which you have described how a certain task can be performed for a certain product. In our case, the task describes peeling a potato:

The task works and at some point in your Vegetables Soup publication you realise you need to write a similar task about peeling cucumbers. The task is exactly the same, except the product name. So naturally you want to reuse the existing written task. For this we re-write the task so that instead of the product potatoes it contains a key reference:
<ph keyref="vegetable"/>
Next we need to define in our DITA Map the vegetable key and bind it to a specific value in the potatoes context:
 <topicref href="potatoes_overview.dita" keyscope="potatoes">
  <!-- Define the vegetable key value in this key scope -->
  <keydef keys="vegetable">
   <topicmeta>
    <keywords>
     <keyword>potatoes</keyword>
    </keywords>
   </topicmeta>
  </keydef>
  <!-- Reference to the common task -->
  <topicref href="peeling.dita"/>
 </topicref>
and add in our DITA Map another key scope with the overview and the task which deal with cucumbers peeling:
 <topicref href="cucumbers_overview.dita" keyscope="cucumbers">
  <!-- Define the vegetable key value in this key scope -->
  <keydef keys="vegetable">
   <topicmeta>
    <keywords>
     <keyword>cucumbers</keyword>
    </keywords>
   </topicmeta>
  </keydef>
  <!-- Reference to the common task -->
  <topicref href="peeling.dita"/>
 </topicref>
As you may have noticed, we have not used the key scope names for anything. Just by defining the key scopes, we made the product name to be expanded differently in both contexts. But our Vegetables Soup publication may also contain a topic which lists all possible vegetables. This topic is defined in a context outside any key scope:
<topicref href="vegetables_over.dita"/>
and this overview topic can refer to each product name using the full keyscope key reference value:
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="vegetables_over">
  <title>Vegetables Overview</title>
  <body>
    <p>This is an overview of all vegetables necessary to make soup. You will learn how to use
      vegetables like <ph keyref="potatoes.vegetable"/> and <ph keyref="cucumbers.vegetable"/> to
      make a great starter soup.</p>
  </body>
</topic>

As stated before, this kind of reuse was not possible using the standard DITA 1.2 standard constructs. As it turns out, with DITA 1.3 we can also implement this kind of reuse using branch filtering. The DITA samples for this post can be downloaded from https://www.oxygenxml.com/forum/files/keyscopesBlogSamples.zip.

As usual any feedback is welcomed.