Docbook - Locally fetching DOCTYPE

By xngo on June 18, 2019

Pointing DOCTYPE to directly use local copies

<!-- Pointing DOCTYPE to use C:\gpl\tools\docbook-xml-4.5\docbookx.dtd -->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" 
                        "file:///C:/gpl/tools/docbook-xml-4.5/docbookx.dtd">

Using this method is not efficient as you will have to change all your files containing DOCTYPE if the path had changed. A better way is to use XML catalog.

Using XML catalog

When you use XML catalog, you don't have to change anything on your files. You only have to create the XML catalog file and tell the XSL processor to use it.

  1. Create the XML catalog. Here is an example:
    <?xml version='1.0'?>
    <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
        <!-- All "-//OASIS//DTD DocBook XML V4.5//EN" will use 
                E:\gpl\tools\docbook-xml-4.5\docbookx.dtd instead of the 1 that 
                    is defined in you file. -->
        <public publicId="-//OASIS//DTD DocBook XML V4.5//EN" 
                            uri="file:///E:/gpl/tools/docbook-xml-4.5/docbookx.dtd"/>
    </catalog>
  2. Tell your XSL processor to use your XML catalog file. Here is an example:
    REM xsltproc will look for XML_CATALOG_FILES environment variable in order to know where is the XML catalog file.
    SET XML_CATALOG_FILES=E:\Projects\test\Catalog.xml
    xsltproc --nonet E:\gpl\tools\docbook-xsl\fo\docbook.xsl myBook.xml > myBook.fo
    call fop -fo myBook.fo -pdf myBook.pdf
    SET XML_CATALOG_FILES=&::

References

  • http://nwalsh.com/docs/articles/xml2003/

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.