• 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
  • Support the site
  • Contact
  • Recordings

Using keys for paths

Posted on 12.02.16

Advanced reuse in DITA Lesson 2: Using keys Using keys for paths
Lesson Progress
0% Complete

Defining the key

To define a key that will contain a path (file path or URL), add the <keydef> element to a map. Use these attributes with the <keydef> element:

  • keys: the name of the key
  • href: the key target
  • format: the type of file indicated by the key

For example:

<keydef keys="product_image" href="images/product_B.png" format="png"/>

Although the key name can contain some special characters, it is a good practice to limit names to letters, numbers, and the underscore character. If you need to use other special characters, check the DITA 1.2 specification.

It is also a good practice to use the format attribute when defining a key. Possible values include “dita”, “ditamap”, “pdf”, “html”, and graphic formats, such as “png” or “svg”.

If you’re defining a key for an external resource, such as a URL, you must use scope=”external” with the <keydef> element:

<keydef keys="our_url" href="http://www.scriptorium.com" scope="external" format="html"/>

The scope attribute prevents the DITA Open Toolkit (or other processors) from attempting to resolve the href target as part of the definition. Because the href attribute points to a web page, the format attribute must contain the value html.

Using the key

To use a key for a file path or URL, use the keyref attribute instead of the href attribute:

<image keyref="product_image"/>
You can use keys (with the keyref attribute) in any element that uses an href attribute to indicate a file path. These elements include (but are not limited to):

  • <image>
  • <xref>
  • <link>
  • <coderef>
  • <topicref>
  • <mapref>
Contributors
  • Simon Bate
  • Jake Campbell
  • Gretyl Kinsey
Previous Topic
Back to Lesson
Next Topic

sidebar

Blog Sidebar

  • Scriptorium logo
    Maximize the value of your content. Read more.
  • Scriptorium logo
    Need DITA help? We offer flat-rate consulting. Get help.
  • Scriptorium logo
    Already in DITA and need support? Contact us.
RSSTwitter

Want to add content? Join the ditatraining GitHub repository.

  • Home
  • Sponsor
  • News
  • Contact
  • Privacy

Maintained by Scriptorium Publishing

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