What is the syntax for creating links to related topics and content in DITA?
In DITA XML, creating links to related topics and content is essential for providing a seamless reading experience and aiding users in exploring relevant information. You can achieve this by using the <xref> element to establish hyperlinks to other DITA topics or resources within your documentation. Here’s how to create these links:
1. Link to a Related Topic: To link to a topic related to the current content, you can use the <xref> element with the ‘href’ attribute. Specify the target DITA file (e.g., “related-topic.dita”) in the ‘href’ attribute to point to the related topic.
Example:
<p>For more information on this topic, please refer to the following related topic:</p>
<xref href="related-topic.dita">Related Topic</xref>
This code creates a link within your DITA content that leads readers to the “Related Topic” DITA file.
2. Link to External Resources: In addition to internal topic linking, you can also use the <xref> element to create links to external resources, such as websites, PDF documents, or online references. Simply specify the URL in the ‘href’ attribute.
Example:
<p>For further details, you can consult the <xref href="https://www.example.com">external resource</xref> on the official website.</p>
This code generates a hyperlink to an external resource, directing users to the provided URL.
3. Cross-Reference within the Same Topic: If you need to cross-reference elements within the same DITA topic, you can use the <xref> element without the ‘href’ attribute. Instead, specify the target element’s ID using the ‘keyref’ attribute.
Example:
<p>Refer to <xref keyref="table-1">Table 1</xref> for a detailed breakdown.</p>
<table id="table-1">
<title>Table 1: Data Summary</title>
<!-- Table content here -->
</table>
This code establishes an intra-topic link, directing readers to “Table 1” within the same topic using the ‘keyref’ attribute.