How is conkeyref different from conref in DITA?

Conkeyref and conref are both mechanisms in DITA for reusing content. However, they differ in their scope and granularity. Conref focuses on whole topics, while conkeyref allows for more precise and selective reuse of specific elements or attributes within topics.

Conref (Content Reference)

Conref allows for the referencing of entire topics. This is useful when the goal is to reuse entire content pieces in different contexts, primarily at the topic level.

For example, if there is a need to reuse a complete topic about “Product A” in various user guides, conref can be used to reference the entire “Product A” topic in different documents:

<conref href="product_a.dita"/>

Conkeyref (Key-based Content Reference)

Conkeyref, conversely, offers more granular control. It permits the referencing of specific elements or attributes within topics, thus allowing selective content reuse.

In the same “Product A” topic, one might want to reuse the product name while providing different descriptions in various documents. Conkeyref facilitates the referencing of just the product name using a key:

          <name conkeyref="p1"/>

The source topic assigns a key (id=”p1″) to the element or attribute intended for reference. The target topic uses the key reference (conkeyref=”p1″) to specify the content to be reused. This approach provides fine-grained control over content reuse.