XML technologies / DocBook / Customizing DocBook / Changing and adding attributes / Adding new attributes to a specific element

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

Suppose the element chapter needs an optional attribute proofreadfrom to identify who has proofread a text. Its value should be an abbreviation or a name.

Customizing DocBook 4

For DocBook 4, proceed as follows:

 

Procedure: Adding proofreadfrom to chapter for DocBook 4

  1. Declaring proofreadfrom
    Create a new file and define the attribute proofreadfrom as a parameter entity as follows:

<!ENTITY % proofreadfrom.attrib "proofreadfrom CDATA #IMPLIED">

 

  1. Adding to the attribute list of chapter
    Add the newly defined parameter entity to the attribute list of chapter. For your customization, use %local.chapter.attrib;:

<!ENTITY % local.chapter.attrib "%proofreadfrom.attrib;">

  1. Loading the DocBook DTD
    Add these lines to your customization file to load the DocBook DTD:

<!ENTITY % DocBookDTD PUBLIC 
   "-//OASIS//DTD DocBook XML V4.5//EN" 
   "http://www.docbook.org/xml/4.5/docbookx.dtd"> 
%DocBookDTD;

  1. Using the customization file
    Use the customization file instead of the original DocBook file (see Validating with a DocBook 4 customization file).

Customizing DocBook 5

For DocBook 5, proceed as follows:

 

Procedure: Adding proofreadfrom to chapter for DocBook 5

  1. Creating the customization file
    Create a customization file with this content:

<grammar ns="http://docbook.org/ns/docbook" xmlns:db="http://docbook.org/ns/docbook" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0"> 
  <include href="docbook.rng"/> 
  <!-- Erweitern: --> 
</grammar>

default namespace db = "http://docbook.org/ns/docbook" 
include "docbook.rnc" 
# Erweitern

  1. Defining proofreadfrom
    Add this line:

<define name="db.proofreadfrom.attribute"> 
    <attribute name="proofreadfrom"> 
        <a:documentation>Which person proofread this text?</a:documentation> 
    </attribute> 
</define>

db.proofreadfrom.attribute = 
  ## Which person proofread this text? 
  attribute proofreadfrom { text }

 

  1. Extending the attribute list of chapter
    Finally, add your new attribute after the preceding comment:

<define name="db.chapter.attlist" combine="interleave"> 
    <optional> 
        <ref name="db.proofreadfrom.attribute"/> 
    </optional> 
</define>

db.chapter.attlist &= db.proofreadfrom.attribute?

  1. Using the customization file
    Use the customization file instead of the original DocBook file (see Validating with a DocBook 5 customization file).

  

back to top