When using content in the context of different maps, it is often necessary to have the same semantic or rhetorical relationship resolve to different resources in different map contexts. For example, a content reference to a phrase element containing the product name needs to resolve to different phrase elements in different product-specific maps. The DITA key reference facility satisfies this requirement by providing an indirect addressing mechanism that separates references (topicrefs, conrefs, cross references, etc.) from the direct address of the target. Linking elements can refer to "key names" that are then bound to specific resources by maps. Different maps can bind the same key names to different resources. This form of indirection is "late bound" because the binding of key names to resources is determined at processing time based on the current set of key definitions for the map context rather than from a static binding created when a topic or map is authored.
Keys are defined within maps. Key names are defined using the @keys attribute on <topicref> elements (or specializations of topicref, such as <keydef>).
The value of the @keys attribute is one or more space-separated key names. Key names consist of characters that are legal in a URI. The case of key names is significant. The following characters are prohibited in key names: "{", "}", "[", "]", "/", "#", "?", and whitespace characters.
A key may be bound simultaneously to several resources:
For the purposes of determining the effective key definitions for the key space represented by a given root map, a map tree is determined by considering only directly-addressed, local-scope maps descending from the root map. The order of subordinate maps is determined by the document order of the topicrefs that point to them. Indirect references to maps with key references are necessarily ignored until after the key space is determined.
For a given key there is at most one effective definition within a key space. A key definition is the effective definition for a given key if it is the first, in document order, within the map document that contains it, and is the first in the map tree in breadth-first order. It is not an error for the same key name to be defined more than once within a map or map tree, and duplicate key definitions should be ignored without warning.
Key definitions are not scoped by the map document within which they occur or by the element hierarchy of their containing map document. Keys do not have to be declared before they are referenced. The key space is effective for the entire document, so the order of key definitions and key references relative to one another within the map hierarchy is not significant, and keys defined in any map in the map tree are available for use with key references from all maps and topics processed in the context of the root map.
For key definitions in a submap to be included in the key space, there must be a direct URI reference to that submap from another directly-addressed map in the map tree. However, if that same submap is referenced indirectly and has no direct URI reference as a backup (using @keyref without providing a fallback @href value, or using @conkeyref without providing a fallback @conref value), that reference is ignored for purposes of constructing the key space, and the definitions in that submap consequently do not enter into the construction of the key space at that point.
The effective keys for a given map may be affected by conditional processing (filtering). Filtering should be applied before determining effective key definitions. However, processors may determine effective key bindings before filtering. Consequently, different processors may produce different effective bindings for the same map when there are key definitions that may be filtered out based on their select attributes.
A relative URI reference in a key definition is resolved relative to the base URI established for the location of the key definition rather than relative to the various locations of references using the key.
For topic references, image references, and navigation link relationships (<link>, <xref>, and elements that take @keyref but not @href), resources may be addressed by key using the @keyref attribute. For content reference relationships, resources may be addressed by key using the @conkeyref attribute.
If both @keyref and @href are specified, the @href value is used as a fallback address when the key reference cannot be resolved to a resource. If both @conkeyref and @conref are specified, the @conref value is used as a fallback address when the key cannot be resolved.
For references to topics, maps, and non-DITA resources, the value of the @keyref attribute is simply a key name: keyref="topic-key".
For references to non-topic elements within topics and non-topicref elements within maps, the value of the @keyref attribute is a key name, a solidus ("/"), and the ID of the target element: keyref="topic-key/some-element-id".
<topic id="topicid"> <title>Example referenced topic</title> <body> <p id="para-01">Some content.</p> </body> </topic>and this key definition:
<map> <topicref keys="myexample" href="file.dita" /> </map>
A keyref of the form "myexample/para-01 resolves to the <p> element in the topic. The key reference would be equivalent, in the context of this map, to the URI reference file.dita#topicid/para-01.
A key reference to a topicref element where the linking element specifies a format value of "ditamap" addresses the topicref element itself as though the topicref element had been addressed by ID. In particular, a topicref with a key reference to another topicref and a format value of "ditamap" is a use of the map branch rooted at the referenced topicref.
When a key definition is bound to a resource addressed by @href or @keyref and does not specify "none" for the @linking attribute, all references to that key definition become navigation links to the bound resource. When a key definition is not bound to a resource or specifies "none" for the @linking attribute, references to that key do not become navigation links.
When a key definition has a <topicmeta> subelement, elements that refer to that key and that are empty may get their effective content from the first matching subelement of the <topicmeta> subelement of the key-defining topicref.
When a key definition has no @href value, references to that key will not result in a link, even if they do contain an @href attribute of their own. If the key definition also does not contain a <topicmeta> subelement, empty elements that refer to the key (such as <link keyref="a"/> or <xref keyref="a" href="fallback.dita"/>) are removed.
For key reference elements that become navigation links, if there is no matching element in the key definition, normal link text determination rules apply as for <xref>.
If a referencing element contains a key reference with an undefined key, it is processed as if there were no key reference, and the value of the @href attribute is used as the reference. If the @href attribute is not specified either, the element is not treated as a navigation link. If it is an error for the element to be empty, an implementation may give an error message, and may recover from this error condition by leaving the key reference element empty.
The effective resource bound to the <topicref> element is determined by resolving all intermediate key references. Each key reference is resolved either to a resource addressed directly by URI reference in an @href attribute, or to no resource. Processors may impose reasonable limits on the number of intermediate key references they will resolve. Processors should support at least three levels of key references.
The attributes that are common to a key definition element and a key reference element using that key, other than the @keys and @id attributes, are combined as for content references, including the special processing for the @xml:lang, @dir, and @translate attributes. There is no special processing associated with either the @locktitle or the @lockmeta attributes when attributes are combined.
(Non normative)
<map> ... <topicref keys="apple-definition" href="topics/glossary/apple-gloss-en-US.dita" /> ... </map>
In this example, the topicref is acting as both a key definition and contributing to the navigation structure of the map, meaning the topic apple-gloss-en-US.dita will be processed as it would be if the @keys attribute were not present.
<map domains="(map mapgroup)"> ... <keydef keys="apple-definition" href="topics/glossary/apple-gloss-en-US.dita" /> ... </map>
Because the <keydef> element sets the default value of the @processing-role attribute to "resource-only", the key definition does not contribute to the map's navigation structure, but only serves to establish the key-to-resource binding for the key "apple-definition".
<map domains="(map mapgroup)"> ... <keydef keys="load-toner" href="topics/tasks/model-1235-load-toner-proc.dita" /> <keydef keys="load-toner" href="topics/tasks/model-4545-load-toner-proc.dita" /> ... </map>
In this example, only the first definition in document order of the "load-toner" key is effective, so all references to the key within the scope of the root map will resolve to the topic model-1235-load-toner-proc.dita, not topic model-4545-load-toner-proc.dita.
<map domains="(map mapgroup)"> ... <keydef keys="file-chooser-dialog" href="topics/ref/file-chooser-osx.dita" platform="osx" /> <keydef keys="file-chooser-dialog" href="topics/tasks/file-chooser-win7.dita" platform="windows7" /> ... </map>
In this example, both key definitions use the @platform metadata attribute to indicate that they apply to different operating system platforms. In this case, the effective key definition is determined not just by the order in which the definitions occur but whether the active value of @platform is "osx" or "windows7" when the key space is determined or the key is resolved. In this case both key definitions are potentially effective because they have distinct values for conditional attributes. Note that if no active value is specified for the @platform condition when determining the effective keys, then both of the definitions are effective and thus the first one in document order is the effective definition.
<map domains="(map mapgroup)"> ... <keydef keys="file-chooser-dialog" href="topics/ref/file-chooser-osx.dita" platform="osx" /> <keydef keys="file-chooser-dialog" href="topics/tasks/file-chooser-win7.dita" platform="windows7" /> <keydef keys="file-chooser-dialog" href="topics/tasks/file-chooser-generic.dita" /> ... </map>
In this case, with an explicitly-configured default behavior of "exclude", if no active value for the platform condition is specified, the third definition will be the effective definition, binding the key "file-chooser-dialog" to the topic file-chooser-generic.dita.
Root map: <map domains="(map mapgroup)"> <keydef keys="toner-specs" href="topics/reference/toner-type-a-specs.dita" /> <mapref href="submap-01.ditamap"/> <mapref href="submap-02.ditamap"/> </map> submap-01.ditamap: <map domains="(map mapgroup)"> <keydef keys="toner-specs" href="topics/reference/toner-type-b-specs.dita" /> <keydef keys="toner-handling" href="topics/concepts/toner-type-b-handling.dita" /> </map> submap-02.ditamap: <map domains="(map mapgroup)"> <keydef keys="toner-specs" href="topics/reference/toner-type-c-specs.dita" /> <keydef keys="toner-handling" href="topics/concepts/toner-type-c-handling.dita" /> <keydef keys="toner-disposal" href="topics/tasks/toner-type-c-disposal.dita" /> </map>
Key | Bound resource |
---|---|
toner-specs | toner-type-a-specs.dita |
toner-handling | toner-type-b-handling.dita |
toner-disposal | toner-type-c-disposal.dita |
The binding for the key "toner-specs" in the root map is effective because it is the first encountered in a breadth-first traversal of the map tree. The binding for the key "toner-handling" to the definition in submap-01.ditamap is effective because submap-01 is included before submap-02 and therefore comes first in the map tree. The binding for the key "toner-disposal" is effective because it is the only definition of the key in the map tree.
<map domains="(map mapgroup)"> <keydef keys="product-name"> <topicmeta> <keywords> <keyword>Thing-O-Matic</keyword> </keywords> </topicmeta> </keydef> </map>
<topic id="topicid"> <title>About the <keyword keyref="product-name"/> product</title> </topic>
Normal processing results in the effective title text "About the Thing-O-Matic product".
<map domains="(map mapgroup)"> <keydef keys="yaw-restrictor" href="parts/subassem/subassm-9414-C.dita" > <topicmeta> <keywords> <keyword>yaw restrictor assembly</keyword> </keywords> </topicmeta> </keydef> </map>
When referenced from a <keyword> element with no directly-specified content, normal processing sets the effective content of the keyword to "yaw restrictor assembly" and makes the keyword a navigation link to the topic subassm-9414-C.dita.
<topicref keys="a" href="http://www.a..." scope="external"> <topicmeta> <linktext>This links to A2</linktext> <shortdesc>Because it does.</shortdesc> </topicmeta> </topicref>
The link in c.dita now resolves to an external URI reference when author 3 builds it (without affecting how it resolves for the other two reusers).
<topicref keys="a"> <topicmeta> <linktext>This is just text.</linktext> </topicmeta> </topicref>
<topicref keys="prodname"> <topicmeta> <linktext>My Product</linktext> </topicmeta> </topicref>
<topicref keys="prodname"> <topicmeta> <linktext>Another Product</linktext> </topicmeta> </topicref>
The keyword now resolves to "Another Product" for author 2, while continuing to resolve to "My Product" for author 1.
<topicref keys="blat-overview blat-intro blat-example blat-reference" href="blat-overview.dita"/>
<topicref keys="blat-overview blat-intro blat-example blat-reference foobar" href="foobar.dita"/>
<topicref keys="overview" href="blat-overview.dita"/>
<link keyref="overview" href="blat-overview.dita"/>
<topicref keys="overview"/>
The link element which uses keyref="overview" is now removed, because there is no target and no link text.
Return to main page.
DITA v1.2 CD 03
Copyright © OASIS Open 2005, 2010. All Rights Reserved.