How do you create and differentiate between hyperlink, xref, and link elements in DITA?
In DITA XML, you can create and differentiate between hyperlink, xref, and link elements to establish various types of connections between topics and resources. These elements serve different purposes and are structured as follows:
1. Hyperlink ( <link> ): Hyperlinks in DITA XML are used to create explicit references to external resources, websites, or files. They are similar to standard HTML hyperlinks and are typically used when you need to link to content outside of your DITA documents. You can specify the target URL using the href
attribute.
Example:
Here’s an example of a <link>
element in DITA XML:
<link href="https://example.com" />
2. Cross-Reference ( <xref> ): Cross-references, defined with the <xref>
element, are used for creating links within your DITA documents. They help you reference other topics or elements within the same content set. The href
attribute specifies the target DITA topic, and you can use the format
attribute to specify the desired format for rendering the cross-reference.
Example:
Here’s an example of a <xref>
element in DITA XML:
<xref href="related-topic.dita" format="html" />
3. Generic Link ( <linktext> ): The <linktext>
element allows you to create custom link text for any type of link or cross-reference. It’s particularly useful when you want to provide descriptive or meaningful link text, different from the target’s title or heading.
Example:
Here’s an example of a <linktext>
element in DITA XML:
<linktext>Learn More</linktext>