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:

The following example explains this mechanism:

  1. 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.

  2. 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 attribute id or xml: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>

  1. 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/

  2. Creating a target database
    Create a file representing the structure from step 3. It is usually named olink.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 element document contains, in the attribute targetdoc, the document ID (see step 2). The attribute baseuri is required only if you generate no chunk files for HTML. The target file declared in the internal subset is inserted here (&howto.xml.target;).

  1. 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.

  1. Inserting olinks
    Insert your olink elements into the document. For example, to create a cross-document reference from the file howtoxslt.xml to a section in the file howtoxml.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 attribute xlink:href.
xlink:href: identifies the document ID before the hash sign (#), equivalent to targetdoc, followed by the target ID (targetptr).

Both cases reference the file howtoxml.xml, whose document ID is howtoxml. The olink element references a section with the ID xml.xmlparser.

  1. Generating the target format
    Finally, generate your target format using the two parameters current.docid and target.database.document in 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

  

back to top