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
Declaring
proofreadfrom
Create a new file and define the attributeproofreadfromas a parameter entity as follows:
<!ENTITY % proofreadfrom.attrib "proofreadfrom CDATA #IMPLIED">Adding to the attribute list of
chapter
Add the newly defined parameter entity to the attribute list ofchapter. For your customization, use%local.chapter.attrib;:
<!ENTITY % local.chapter.attrib "%proofreadfrom.attrib;">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;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
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"
# ErweiternDefining
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 }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?Using the customization file
Use the customization file instead of the original DocBook file (see Validating with a DocBook 5 customization file).
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de