Key Scopes

Keys can be limited to a specific scope by defining key scopes. This mechanism can be used to fill template topics, that are referenced multiple times, with different data.

Sample project: key-scopes.zip



map.ditamap

The map.ditamap references the technical-data.dita twice. The @keyscope attributes on the <topicref> elements define two key scopes, one for the Galaxy S7 and one for the iPhone 7.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map>
  <title>keyscopes</title>

  <!-- The same technical data topic is used -->
  <topicref href="technical-data.dita" keyscope="galaxys7">
    <mapref href="database-galaxys7.ditamap"/>
  </topicref>

  <topicref href="technical-data.dita" keyscope="iphone7">
    <mapref href="database-iphone7.ditamap"/>
  </topicref>
</map>

technical-data.dita

The technical-data.dita is a template topic, that is filled with the data from the database-galaxys7.ditamap and from the database-iphone7.ditamap.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="technical-data">
  <title>technical data</title>
  <body>
    <p>Technical Data of <keyword keyref="product"/></p>
    <table frame="none" rowsep="0" colsep="0">
      <tgroup cols="2">
        <colspec colname="c1" colnum="1" colwidth="25*"/>
        <colspec colname="c2" colnum="2" colwidth="75*"/>
        <tbody>
          <row>
            <entry>Device Type</entry>
            <entry><keyword keyref="device-type"/></entry>
          </row>
          <row>
            <entry>OS</entry>
            <entry><keyword keyref="os"/></entry>
          </row>
          <row>
            <entry>Dimensions</entry>
            <entry><keyword keyref="dimensions"/></entry>
          </row>
          <row>
            <entry>Weight</entry>
            <entry><keyword keyref="weight"/></entry>
          </row>
          <row>
            <entry>Display</entry>
            <entry><keyword keyref="display"/></entry>
          </row>
          <row>
            <entry>Resolution</entry>
            <entry><keyword keyref="resolution"/></entry>
          </row>
          <row>
            <entry>Pixel Density</entry>
            <entry><keyword keyref="pixel-density"/></entry>
          </row>
          <row>
            <entry>Processor</entry>
            <entry><keyword keyref="processor"/></entry>
          </row>
        </tbody>
      </tgroup>
    </table>
  </body>
</topic>

database-galaxys7.ditamap

The database-galaxys7.ditamap defines multiple keys, that contain technical data specific for the Galaxy S7.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map>
  <title>Galaxy S7</title>
  <keydef keys="product">
    <topicmeta>
      <keywords>
        <keyword>Galaxy S7</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="device-type">
    <topicmeta>
      <keywords>
        <keyword>Smartphone</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="os">
    <topicmeta>
      <keywords>
        <keyword>Android</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="dimensions">
    <topicmeta>
      <keywords>
        <keyword>150.9 x 72.6 x 7.7 mm</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="weight">
    <topicmeta>
      <keywords>
        <keyword>157 g</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="display">
    <topicmeta>
      <keywords>
        <keyword>5.5 inches</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="resolution">
    <topicmeta>
      <keywords>
        <keyword>1440 x 2560 pixels</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="pixel-density">
    <topicmeta>
      <keywords>
        <keyword>534 ppi</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="processor">
    <topicmeta>
      <keywords>
        <keyword>Qualcomm Snapdragon 820 MSM8996, Quad-core, 2200 MHz</keyword>
      </keywords>
    </topicmeta>
  </keydef>
</map>

database-iphone7.ditamap

The database-iphone7.ditamap defines multiple keys, that contain technical data specific for the iPhone 7.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map>
  <title>iPhone 7</title>
  <keydef keys="product">
    <topicmeta>
      <keywords>
        <keyword>iPhone 7</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="device-type">
    <topicmeta>
      <keywords>
        <keyword>Smartphone</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="os">
    <topicmeta>
      <keywords>
        <keyword>iOS</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="dimensions">
    <topicmeta>
      <keywords>
        <keyword>158.2 x 77.9 x 7.3 mm</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="weight">
    <topicmeta>
      <keywords>
        <keyword>188 g</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="display">
    <topicmeta>
      <keywords>
        <keyword>5.5 inches</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="resolution">
    <topicmeta>
      <keywords>
        <keyword>1080 x 1920 pixels</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="pixel-density">
    <topicmeta>
      <keywords>
        <keyword>401 ppi</keyword>
      </keywords>
    </topicmeta>
  </keydef>
  <keydef keys="processor">
    <topicmeta>
      <keywords>
        <keyword>Apple A10 Fusion, Quad-core, 2340 MHz</keyword>
      </keywords>
    </topicmeta>
  </keydef>
</map>

Galaxy S7 Result

The following table is rendered for the Galaxy S7.

Technical Data of Galaxy S7

Device Type Smartphone
OS Android
Dimensions 150.9 x 72.6 x 7.7 mm
Weight 157 g
Display 5.5 inches
Resolution 1440 x 2560 pixels
Pixel Density 534 ppi
Processor Qualcomm Snapdragon 820 MSM8996, Quad-core, 2200 MHz

iPhone 7 Result

The following table is rendered for the iPhone 7.

Technical Data of iPhone 7

Device Type Smartphone
OS iOS
Dimensions 158.2 x 77.9 x 7.3 mm
Weight 188 g
Display 5.5 inches
Resolution 1080 x 1920 pixels
Pixel Density 401 ppi
Processor Apple A10 Fusion, Quad-core, 2340 MHz