You want to set a “link” but you do not know which DocBook element to use.
DocBook distinguishes between two link types:
Internal Links or Cross-References. Used primarily with xref
.
External Links. Used primarily with link
.
There are several differences between xref
and
link
. An xref
is used for cross
referencing another part of the document. In its simplest form,
you only need an ID value of the object that you want to refer:
The DocBook XSL stylesheets take care of resolving the
xref
. By default, it replaces the xref
element with a number and the title of the reference. It could
look like this:
Read an introduction in Section 1.1, “About Tea”.
The text Section 1.1, “About Tea”
is a “hot
link” and points to the respective section. Using
xref
for cross-references has several advantages:
Whenever a text of a title changes, all xref
s
pointing to it will automatically change too.
During validation, the linkend
attribute is checked for existence.
During resolution, additional words like “Section”, “Chapter”, or “Figure” are automatically inserted according to the document language.
You do not have to care about numbering.
For further customization, use the xrefstyle
attribute
In contrast, a link
is used in most cases for
external links.
Using link
has the following advantages:
Usually no automatic resolution is performed (only if you use
xlink:href
).
No validation is necessary between source and target.
The link content can be created manually.
Additional inline elements are allowed.
The differences between xref
and link
are collected in Table 1.5, “Differences Between xref
and link
”.
xref
and link
Topic | xref | link |
---|---|---|
TDG[a] Definition | A cross-reference to another part of the document | A hypertext link |
TDG Link | http://www.docbook.org/tdg51/en/html/xref.html | http://www.docbook.org/tdg51/en/html/link.html |
Content Model | empty | text and inline elements |
Resolution | Yes, automatically during transformation | No, link content must be definied manually |
ID/IDREF Checking | Yes | No[b] |
Restrictions | Only cross referencing to elements that contain a title | No restrictions |
[a] The Definitive Guide, see http://www.docbook.org/tdg51/en/html/docbook.html .[b] Checking can be performed, when |
Project@GitHub | Issue#6 |