XML technologies / DocBook / The DocBook XSL stylesheets / Creating cross-document references
(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)
The section Cross-references and links introduced the ways to use reference-like elements in your document. Typical cross-references use the datatype ID at their source and, at the target, IDREF. A schema can therefore check them.
If this mechanism is neither desirable nor possible, and URI-based linking is unsuitable, these cross-references will not help. DocBook provides the alternative element olink. The basic approach of olink is as follows:
Before using olinks, you should know the following:
OLink works only with DocBook documents whose source code you have.
OLink creates dependencies between documents that do not arise with a standalone document.
Links are checked during transformation rather than validation, so typing errors are detected later in the process.
If references differ between (X)HTML and FO/PDF, you need separate target files.
Whenever a document changes, regenerate its target file too. Automate this using makefiles, shell or Bash scripts, Ant, or similar tools.
The following example explains this mechanism:
Which documents should be linked?
First decide which documents to link. This example assumes two how-to documents, one about XML and one about XSLT. Together, these are called a document collection.Assigning a document ID
Assign each document an ID unique throughout the collection. You can add further documents later. Put a unique identifier on each DocBook document’s root element in the attributeidorxml:id. The documents in this example are:
Für DocBook4:
<article id="xmlhowto"> ... </article>
<article id="xslthowto"> ... </article>
Für DocBook5:
<article xml:id="xmlhowto"> ... </article>
<article xml:id="xslthowto"> ... </article>Choosing the (X)HTML output hierarchy
Plan the directory structure for (X)HTML to establish relative positions and keep things clear. This example uses the following structure:doku
|
+-- howtoxml/
|
+-- howtoxsl/Creating a target database
Create a file representing the structure from step 3. It is usually namedolink.db, though other filenames are possible. These contents match the structure from step 3:
Example: Target database olink.db
<!DOCTYPE targetset SYSTEM
"http://docbook.sourceforge.net/release/xsl/current/common/targetdatabase.dtd"
[
<!ENTITY howto.xml.target SYSTEM "xmlhowto.target.db">
<!ENTITY howto.xslt.target SYSTEM "xslthowto.target.db">
]>
<targetset>
<targetsetinfo>Beschreibung Ihrer Datenkollektion</targetsetinfo>
<sitemap>
<dir name="doku">
<dir name="howtoxml">
<document targetdoc="xmlhowto" baseuri="howtoxml.html">&howto.xml.target;</document>
</dir>
<dir name="howtoxslt">
<document targetdoc="xslthowto" baseuri="howtoxsl.html">&howto.xslt.target;</document>
</dir>
</dir>
</sitemap>
</targetset>Lines 4 and 5: Declare for each document in your collection an entity. The file is generated separately and contains all targets for that document.
Line 7: The root element
Line 8: A short description to distinguish document collections.
Line 9: Describes the structure planned in step 3.
Lines 10 and 14: A parent directory containing all other directories.
Line 11: References the directory holding the XML or XSLT how-to files (see step 3).
Line 12: The elementdocumentcontains, in the attributetargetdoc, the document ID (see step 2). The attributebaseuriis required only if you generate no chunk files for HTML. The target file declared in the internal subset is inserted here (&howto.xml.target;).
Generating a target file
For each document in your collection, generate a target file containing all potential cross-reference targets. Create it as follows:
xsltproc --stringparam targets.filename xmlhowto.target.db \
--stringparam collect.xref.targets "only" \
DB/html/docbook.xsl howtoxml.xml
xsltproc --stringparam targets.filename xslthowto.target.db \
--stringparam collect.xref.targets "only" \
DB/html/docbook.xsl howtoxslt.xml This example also specifies the target filename using the parameter
collect.xref.targets. This distinguishes the individual target files.
Inserting
olinks
Insert yourolinkelements into the document. For example, to create a cross-document reference from the filehowtoxslt.xmlto a section in the filehowtoxml.xml:
For DocBook 4, enter:
<olink targetdoc="howtoxml" targetptr="xml.xmlparser"/>
targetdoc: references the target document’s ID.targetptr: references an ID within the target document.
For DocBook 5, you need XLinks:
<olink xlink:role="http://docbook.org/xlink/role/olink" xlink:href="xmlhowto#xml.xmlparser"/>
xlink:role: identifies the element as a cross-document link. This is necessary because processing uses special syntax in the attributexlink:href.xlink:href: identifies the document ID before the hash sign (#), equivalent totargetdoc, followed by the target ID (targetptr).Both cases reference the file
howtoxml.xml, whose document ID ishowtoxml. Theolinkelement references a section with the IDxml.xmlparser.
Generating the target format
Finally, generate your target format using the two parameterscurrent.docidandtarget.database.documentin the invocation:
xsltproc --output doku/howtoxml/howtoxml.html \
--stringparam current.docid "xmlhowto" \
--stringparam target.database.document "olinkdb.xml" \
DB /html/docbook.xsl howtoxml.xml
xsltproc --output doku/howtoxslt/howtoxslt.html \
--stringparam current.docid "xslhowto" \
--stringparam target.database.document "olinkdb.xml" \
DB/html/docbook.xsl howtoxslt.xml
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de
back to top