Linking in Docbook

1. Building large books and olink
2. Cross Reference into another document
3. olink problem
4. Cross reference to a figure
5. Which type of link to use?

1.

Building large books and olink

Bob Stayton


> Currently I have one large book (about 5000 html files) and just don't have
> enough time to generate the whole document every night.

> Do I understand correctly that splitting the book up into a set of books
> won't help me out here because I still have to generate the whole set in one
> go?

That's correct, if you are trying to cross reference among the books using <xref> and <link>. Those elements use the ID/IDREF mechanism to resolve links, and the ID and IDREF must be in the same document.

> Because some of the chapters (books) are quite static / don't change often I
> would like to skip those.

> Do I understand correctly that using olink you can accomplish this?

> For example:

> book
>   chapter 1 - dynamic -> process
>   chapter 2 - dynamic -> process
>   chapter 3 - static  -> skip
>   chapter 4 - dynamic -> process

> or

> set
>   book1 -> process
>     chapter 1 - dynamic -> process
>     chapter 2 - dynamic -> process
>     chapter 3 - static  -> skip
>     chapter 4 - dynamic -> process
>   book2 -> process
>     chapter 1 - dynamic -> process
>     chapter 2 - dynamic -> process
>   book3 -> skip
>     chapter 1
>     chapter 2

Currently the olink in the XSL stylesheets can't quite do what you want. The scenario where it works best looks like this:

book1 -> process
book2 -> process
book3 -> skip

This is a collection of books not inside of a set element, and where you want to form links between the books. By using olink for those links between books, you can avoid having to create one huge set document just to form links. With this scenario, you can process a single book whenever something changes in that book.

But you have to be careful, because when you start using olinks, you create dependencies between your books. Let's say you change a chapter title in book1 and reprocess that book. If your book3 has an olink to that chapter, and that olink element contains no text, then the chapter title link text that was generated the last time book3 was processed is now wrong and needs to be updated. If you use Makefiles, you can have book3 be dependent on book1's target data file, which is generated for olinking. If you are careful to not alter the timestamp on the target data file unless it actually changes, then the dependency works. See sagehill.net (the section on Using Makefiles) for an example.

You can also split a book up into chapter files, and use olinks to link among the book's chapter files. If you use XInclude instead of system entities to assemble the book, then you can have fully valid chapter files. That's a nice feature for writing and editing.

But processing a single chapter with the current stylesheets will always yield "Chapter 1" in the output, because that's the 'document' the processor is seeing. There are two ways around that. One way is to put a fixed "label" attribute on each chapter element, but that loses autonumbering. Who wants to manually maintain chapter numbers? Not me. Or you can process your master book file with the 'rootid' parameter to select a single chapter for output. This still loads and parses the entire book though, so I don't think it speeds things up a lot.

Since all we need is to set the chapter number, I have in mind a new parameter that tells the stylesheet to get the chapter number from the target data file for the book. But that feature isn't implemented yet.

Taking that idea a step further, you could construct a mega table of contents from your target database. It contains all the hierarchy, text, and URL information it needs to do that. So theoretically you could generate something like a complete set TOC for your collection of books, even though you have no set element.

2.

Cross Reference into another document

Bob Stayton



>  I would like to write 
> something like

> <xref targetdocent="software" linkend="emacs"/>

> and have the stylesheet generate the link text as appropriate.

You want to use the new implementation of olinks in the DocBook XSL stylesheets that can generate link text from a link database that has data for all the documents within a cross referencing scope. The olink syntax would be:

<olink targetdoc="software" targetptr="emacs"/>

See: Sagehill.net

You will have to extend the target collection process to include your customization. See the common/targets.xsl stylesheet, in mode="olink.mode".

3.

olink problem

Bob Stayton


Using website, I'm experimenting with olink,


> /usr/local/bin/xsltproc --catalogs --nonet 
> --xinclude -o tests/zielendeseite.html  --stringparam autolayout-file 
> "/usr/home/plexus/ew/pwxsl/kopf/test/netzseite/autolayout.xml" 
> --stringparam target.database.document 
> "/usr/home/plexus/ew/pwxsl/kopf/test/netzseite/website.database.xml" 
> ./../../website/xsl/tabular.xsl tests/zielendeseite.xml)
> Variable $SGML_CATALOG_FILES not set
> warning: failed to load external entity "tests/website.database.xml"
> warning: failed to load external entity "tests/website.database.xml"
> warning: failed to load external entity "tests/website.database.xml"
> warning: failed to load external entity "tests/website.database.xml"
> warning: failed to load external entity "tests/website.database.xml"
> warning: failed to load external entity "tests/website.database.xml"


> May it is possible to avoid this warning?

Website supports *two* olink databases, identified by two different parameters:

website.database.document   - targets in webpages in your layout.xml
target.database.document    - other documents outside of Website

You are setting the parameter for the offsite targets. That leaves the stylesheet to look for the website targets in the default location, which is the current directory. Change the parameter name in your command to 'website.database.document' and it should work.

You only need target.database.document if some of your webpages contain olink references to documents outside of your Website.

4.

Cross reference to a figure

Bob Stayton


> I want to cross reference a figure in a docbook document that is going
> to be converted to HTML. I tried using the Xref element, but I don't
> know how to implement it correctly. After the conversion to HTML, the
> Xref element has been replaced by a triple question mark: "???", so
> something has gone wrong.
>
> This is what I did:
>
> - The Xref element has an attribute "Linkend". I assigned it a value
> "SomeTitle".
> - The figure that I intend to reference has a caption element, which has
> an attribute "ID". I assigned it the value "SomeTitle"
> - I converted the docbook XML document to HTML, using Saxon .
>
> Of course, I want the text "SomeTitle" to appear at the place of the
> reference, but that didn't happen (as described above).

The usual way to reference a figure is to put the ID attribute on the figure element, and then use that id value in the linkend attribute of an xref. That generates something like "Figure 3.2". The stylesheets don't support xrefs to the caption inside a mediaobject inside a figure.

If you don't want the reference to say "Figure 3.1", then you have a couple of options. You can use a link element instead of xref, and supply whatever text you want inside of it. Or you can put an xreflabel attribute on any element, and then any xref that points to the id of that element will use the text of the xreflabel as the generated text. See this refererence for more information on xref options: sagehill.net

5.

Which type of link to use?

Jirka Kosek


> <xref linkend="aa">Some comment</xref>
> ...
> <sect1 id="aa"><title>Comments around this</title></sect1>
> ...
>     I want it to  generate:

> <a href="#aa">Some comment</a>

Use link instead of xref. xref creates text of link automatically, while link lets you specify your own.