DocBook CookBook
Updated
06 Mar 2008
    Linking
       Using xinclude
      +Using xpointer with xmllint <-
    DocBook XSL
    Printing

Resolving xinclude statements with xpointer using xmllint

Problem

You want to use the xpointer function in an xinclude statement in DocBook 5.0 and resolve the xinclude with xmllint.

Example 1, “Bad xinclude example” is a typical xinclude statement that would have worked correctly with DocBook 4.x.

Example 1. Bad xinclude example

<!-- This is INCORRECT -->
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
    href="filename.xml"
    xpointer="xpointer(//title[1])"/>
      


However, with DocBook 5.0, this statement will not work correctly because xpointer sees a reference without a namespace, but the included file is in the DocBook namespace (http://docbook.org/ns/docbook). Therefore, xpointer won't recognize the contents of filename.xml.

Solution

Give the xpointer statement the namespace of the included file. Example 2, “Good xinclude example” shows how to do this:

Example 2. Good xinclude example

<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
    href="filename.xml"
    xpointer="xmlns(db=http://docbook.org/ns/docbook)xpointer(//db:title)"/>
      


Discussion

Namespaces are powerful constructs, but they require attention to detail, especially when you move from a non-namespaced to a namespaced environment.

See Also

Reference