• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Learning DITA

Free DITA training

Free DITA training

  • Log in
  • Register
  • Newsletter
  • Profile
  • Privacy
  • Home
  • About
  • Courses
  • News
  • Resources
    • Recordings
  • Questions?
  • Contact

What is a key?

Posted on 12.02.16

Advanced reuse in DITA Lesson 2: Using keys What is a key?

A DITA key allows you to create a placeholder for a file path or a short piece of text. You create the key name and definition (the text to use in place of the key) in a DITA map;. You refer to a key by specifying the key name in a keyref attribute. The keyref attributes are resolved when topics and maps are transformed into an output format.

The advantage of using a key is that you define the key in one place (in the map), then refer to that key by name throughout all your topics. If the file path or text changes, you only need to change the definition and the new definition is reflected everywhere that the keyref attribute is used.

Keys make it easy to create reusable topics. Because key definitions can be different for each map, a reusable topic that uses keys can contain different file paths or strings, depending on which map it is used in.

For instance, you might create a reusable topic that uses two keys:

  • The key product_name contains the name of a product
  • The key product_image contains the path to a picture of the product

In the map for Product A, product_name could be defined as “Product A” and product_image as “images/ProductA.png”.

In the map for Product B, product_name could be defined as “Product B” and product_image as “images/ProductB.png”.

When your topic is used in the map for Product A, the product name “Product A” is used and the product image shows the correct product. When your topic is used in the map for Product B, the correct product name and image are shown for that product.

You define keys in a DITA map with the <keydef> element, which is a specialization of the <topicref> element.

There are some differences between keys used for paths and keys used for text strings. There are differences in how you define the keys and how you use them. These two uses are described in the next two topics.

Note: This description of keys does not address scoped keys, which were introduced in DITA 1.3. The concept of scoped keys will be addressed in a future LearningDITA course.

Note: There is a third use for keys: they can be used to specify a path to conref content. These “conkeyrefs” are addressed in the next lesson (“Advanced conrefs”).

Contributors
  • Simon Bate
  • Jake Campbell
  • Gretyl Kinsey
Previous Lesson
Back to Lesson
Next Topic

sidebar

Blog Sidebar

  • Scriptorium logo
    Maximize the value of your content. Read more.
  • Scriptorium logo
    Already in DITA and need support? Contact us.
RSSLinkedin

Want to add content? Join the ditatraining GitHub repository.

  • Home
  • News
  • Contact
  • Privacy
  • Cookie Policy

Maintained by Scriptorium Publishing

Logo and site presentation © 2015–2023 Scriptorium Publishing. Content based on the open-source DITA training project.

Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}