Search code examples
xmlxsddocbookdocbook-5

DocBook 5: How do I do variable substitution to replace ${version} by a value?


While writing a large manual in DocBook 5 (which uses an XSD, not DTD), I need to mention the version name in many places. For example, the name of distribution zip includes the version name. That version name changes constantly, so I 'd like to use a variable for that.

How do I do variable substitution in DocBook 5 (which uses an XSD, not DTD)?


Solution

  • An XML entity is a kind of macro or substitutable variable, so I suggest that you use one or more of those. Entities can be declared and referenced in any XML document, even if a DTD is not used for validation.

    Declaration of the version entity (an internal entity):

    <?xml version="1.0"?>
    <!DOCTYPE book [
    <!ENTITY version "Version X">
    ]>
    <book xmlns="http://docbook.org/ns/docbook" version="5.0">
     ...
    </book>
    

    Reference to the version entity:

    <book xmlns="http://docbook.org/ns/docbook" version="5.0">
     ...
     <para>The current version is &version;</para>
    </book>
    

    When the document is parsed, the parser replaces all occurrences of &version; with Version X.

    There are more details and suggestions here: http://www.sagehill.net/docbookxsl/Db5Entities.html.