Skriftlig InfoDITA publishingDITA variablesVariable definitions using topic maps

Variable definitions using topic maps

You can use a topic map to define variables and provide these with values. The map must be included in the bookmap.

On this page

Important

In the procedures, descriptions and examples I use the <keyword> element. In many DITA systems, you can also use other elements. The elements must be defined in the system files that control the publishing system's functionality. Check with your system supplier for more information about this.

I recommend that you standardize the use of the <keyword> element for variables. Although it is permitted to use other elements, it is easier to be consistent. This consistency increases understanding in the team and facilitates maintenance. Especially for new users, it will be easier to identify which elements are variables and which are not.

Defining the variable in a topic map

A standard topic map is used.

This is the required code to define a variable called "VARIABLE" with a value set to "VALUE". The code will not look like this in your editor, since most editors prefer a more user friendly presentation.

<map>
...
<keydef keys="VARIABLE">
  <topicmeta>
    <navtitle>
      <keywords>
        <keyword>VALUE</keyword>
      </keywords>
    </navtitle>
  </topicmeta>
</keydef>
...
</map>

You can create as many <keydef> definitions as you want in the topic map, and each can have any value you want.

If any of the values have normal text that needs translation, the topic map must be included in the files you send to the translator. If you need to do this I recommend that you document each and every variable and explain how they are used.

Tip

To identify the topic map I use to define variables, and make it easier to find, I refer to it as a "keymap". This is not a standard DITA designation. In your database system, I suggest that you establish "Keymap" as a map type in your metadata. Unique identification makes the topic map easier to find.

Using the variable in a topic or in a library topic

The variable "VARIABLE" can be used in a topic or library topic as follows:

<p>
...
<keyword keyref="VARIABLE">
...
</p>

The <keyword> tag can be placed anywhere it is needed. In this example, I've used it in a <p> element, but you could just as easily place it in, say, a <title> or <cmd> element. Use the keyref attribute to retrieve the correct variable.

When you use the <keyword> tag in a topic or topic library, the content of VALUE can be any random text. You can also type whatever you want in the <keyword> tag. When the document is published, the publishing process will automatically retrieve and insert the correct value from the definition. This automatic process means you can insert the <keyword> tag from any topic library or copy it from another topic. Just make sure the keyref attribute points to the correct variable.

Placing the topic map in the publication

The map with the <keydef> definitions must be inserted into the <frontmatter> tag in your bookmap. Use the <mapref> tag.

Tip

These pages only explain how variables are used in DITA publishing. If you want additional explanations about the principle of variables, see under Methodology and especially Using variables in the text.


All external links open in a new window. I take no responsibility for information on external websites, even if I have linked to them. Please report links that do not work.

The information on this page represents my personal opinions and my understanding of the topic being described. Feel free to link to the page, but do not copy large parts of the content without permission. I take no responsibility for any errors, misunderstandings or missing information. I also take no responsibility for any mistakes you may make or cause as a result of incorrect or missing information. You are welcome to contribute with comments, relevant experiences or additional information. See Editor and contact information.