XML technologies / DITA / Specialization / Domains
(Excerpt from “DITA – Der neue Standard für Technische Dokumentation” by Johannes Hentrich)
Domain specialization provides new semantics for topics. Two files are created and edited:
modfile: all elements supplied by the specialized domain are defined in amodfile, that is, a module file. An existing DITAmodfile serves as the template for the specializedmodfile.entfile: contains all parameter entities and text entities for the specialized domain.
The XSLT stylesheets can also be adapted for the new elements.
Domain specialization example
As with topic specialization, first create a model document containing the desired specialized elements. This is strongly recommended especially when their content models contain further elements rather than a simple type such as PCDATA, since some domains include semantic elements with complex content models.
A model document also makes testing the specialization much easier.
This example specializes the element <keyword>. DITA intends it to mark commands, parameters or product names, for example. This broad scope makes the element <keyword> particularly suitable for specialization.
Here, the element <keyword> is specialized to mark components of XML syntax: elements, attributes, text entities and parameter entities.
The specialization should provide these four elements:
<xmlelement>: marks XML elements.<xmlattribute>: marks XML attributes.<textentity>: marks text entities.<parameterentity>: marks parameter entities.
For clarity, this example uses only elements with the simple type PCDATA. Each could contain further elements, but its content model must remain more restrictive than the original. Content-model rules are explained in Flexible extensibility.
Domain specialization requires these steps:
Create a
modfile, a module defining the specialized elements.Create an
entfile defining the domain’s parameter and text entities.Integrate the newly created
modfile into one or more shell DTDs.
First create a mod file defining the new elements.
The easiest way to create a mod file is to copy an existing mod file and adapt it. In the new mod file, add new element declarations and delete those not needed.
Unlike topic specialization, domain specialization often needs only a few declarations from an existing mod file, so creating a new mod file is often quicker than editing one. The following creates a new mod file to specialize the element <keyword>. Proceed as follows:
Create a
modfile calledxmlmarkupDomain.mod.Define the new elements’ parameter entities.
<!ENTITY % xmlelement "xmlelement">
<!ENTITY % xmlattribute "xmlattribute">
<!ENTITY % textentity "textentity">
<!ENTITY % parameterentity "parameterentity">Define the elements and their attributes.
<!ELEMENT xmlelement (#PCDATA)*>
<!ATTLIST xmlelement %univ-atts; outputclass CDATA #IMPLIED>
<!ELEMENT xmlattribute (#PCDATA)*>
<!ATTLIST xmlattribute %univ-atts; outputclass CDATA #IMPLIED>
<!ELEMENT testentity (#PCDATA)*>
<!ATTLIST textentity %univ-atts; outputclass CDATA #IMPLIED>
<!ELEMENT parameterentity (#PCDATA)*>
<!ATTLIST parameterentity %univ-atts; outputclass CDATA #IMPLIED>This example’s attribute definitions include the parameter entity
%univ-atts, which defines practically all available element attributes. The declarationoutputclassadds another standard DITA attribute evaluated during XML-to-HTML processing.
Define the attributes
classfor the new elements.
As in topic specialization, the attribute
classis central: it specifies derivation from the original structures.
In DITA’s
modfiles, definitions for the attributeclassare separated from other attribute definitions for maximum modularity.
The declarations for the four elements’ attributes class are as follows:
<!ATTLIST xmlelement %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/xmlelement ">
<!ATTLIST xmlattribute %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/xmlattribute ">
<!ATTLIST textentity %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/textentity ">
<!ATTLIST parameterentity %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/parameterentity ">The plus sign in the attribute class definition indicates domain specialization. A space is followed by the definition topic/keyword xmlmarkup-d/xmlelement, describing how the element <xmlelement> from the domain xmlmarkup-d derives from the element <keyword> in the topic domain. The new domain name, here xmlmarkup-d, also appears in the corresponding ent file. Convention adds a -d to indicate a domain module. After defining the mapping from topic/keyword to xmlmarkup-d/xmlelement, another space is required to finish the attribute class definition.
Defining the attributes class completes the xmlmarkup.mod file. Using DITA’s usual mod file headings, the xmlmarkup.mod file looks as follows:
<!-- ============================================= -->
<!-- ELEMENT NAME ENTITIES -->
<!-- ============================================= -->
<!ENTITY % xmlelement "xmlelement">
<!ENTITY % xmlattribute "xmlattribute">
<!ENTITY % textentity "textentity">
<!ENTITY % parameterentity "parameterentity">
<!-- ============================================= -->
<!-- ELEMENT DECLARATIONS -->
<!-- ============================================= -->
<!ELEMENT xmlelement (#PCDATA)* >
<!ATTLIST xmlelement %univ-atts; outputclass CDATA #IMPLIED>
<!ELEMENT xmlelement (#PCDATA)*>
<!ATTLIST xmlelement %univ-atts; outputclass CDATA #IMPLIED>
<!ELEMENT xmlattribute (#PCDATA)*>
<!ATTLIST xmlattribute %univ-atts; outputclass CDATA #IMPLIED>
<!ELEMENT testentity (#PCDATA)*>
<!ATTLIST textentity %univ-atts; outputclass CDATA #IMPLIED>
<!ELEMENT parameterentity (#PCDATA)*>
<!ATTLIST parameterentity %univ-atts; outputclass CDATA #IMPLIED>
<!-- ============================================= -->
<!-- SPECIALIZATION ATTRIBUTE DECLARATIONS -->
<!-- ============================================= -->
<!ATTLIST xmlelement %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/xmlelement ">
<!ATTLIST xmlattribute %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/xmlattribute ">
<!ATTLIST textentity %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/textentity ">
<!ATTLIST parameterentity %global-atts; class CDATA "+ topic/keyword xmlmarkup-d/parameterentity ">After creating the new domain’s mod file, create its associated ent file. Proceed as follows:
Create a new
entfile calledxmlmarkupDomain.ent.Add the following declarations to the
xmlmarkupDomain.entfile:
<!ENTITY % xmlmarkup-d-keyword xmlelement | xmlattribute | textentity | parmenterentity“>
<!ENTITY xmlmarkup-d-att "(topic xmlmarkup-d)">The xmlmarkupDomain.ent file declares a parameter entity listing every new domain element and a text entity naming the domain.
DITA convention assigns names in the form Modulname-d-att, here xmlmarkup-d-att.
The keyword topic indicates a topic domain. The keyword map would indicate a map domain. The module name here is xmlmark-up-d, already used in definitions of the attribute class in the xmlmarkupDomain.mod file.
With DITA’s usual ent file headings, the xmlmarkupDomain.ent file looks as follows:
<!--================================================== -->
<!-- ELEMENT EXTENSION ENTITY DECLARATIONS -->
<!-- ================================================= -->
<!ENTITY % xmlmarkup-d-keyword "xmlelement | xmlattribute | textentity | parmenterentity">
<!-- ================================================= -->
<!-- DOMAIN ENTITY DECLARATION -->
<!-- ================================================= -->
<!ENTITY xmlmarkup-d-att "(topic xmlmarkup-d)" >Once the xmlmarkupDomain.mod file and the xmlmarkupDomain.ent file are ready, integrate them into a shell DTD. Integration order matters: for multiple entity declarations, a DTD always uses the first and ignores subsequent ones. Remember this when overriding entities included from other files.
First import the ent file. It contains module-specific entity declarations overriding standard definitions in the mod files. Then import the mod file, containing element parameter entities and attribute lists.
Create the shell DTD as follows:
Copy the
concept.dtdfile and rename it, for exampledomain_concepts.dtd.In the section
DOMAIN ENTITY DECLARATIONS, insert the parameter entity for thexmlmarkupDomain.entfile.
<!ENTITY % xmlmarkup-d-dec SYSTEM "xmlmarkupDomain.ent">
%xmlmarkup-d-dec;In the section
DOMAIN EXTENSIONS, add the parameter entityxmlmarkup-d-keyword. This parameter entityxmlmarkup-d-keywordwas defined in themarkupDomain.entfile.
<!ENTITY % keyword "keyword | %xmlmarkup-d-keyword;">Since the element
<keyword>was specialized, theDOMAIN EXTEN-SIONS-section requires a change to the% keywordparameter entity.
In the section
DOMAINS ATTRIBUTE OVERRIDE, insert the domain-name parameter entity, defined in thexmlmarkupDomain.entfile.
<!ENTITY included-domains "&ui-d-att; &hi-d-att; &prd-att; &sw-d-att; &ut-d-att; &indexing-d-att; &xmlmarkup-d-att;">Add the following entry to the shell DTD’s section
DOMAIN ELEMENT INTEGRATION:
<!ENTITY % xmlmarkup-d-def SYSTEM "xmlmarkup.mod">
%xmlmarkup-d-def;The name
xmlmarkup-d-deffollows DITA conventions, with-dindicating a domain and-defa definition. With the usual headings, the shell DTD contains these domain specialization entries:
<!-- ============================================= -->
<!-- DOMAIN ENTITY DECLARATIONS -->
<!-- ============================================= -->
<!ENTITY % xmlmarkup-d-dec SYSTEM "xmlmarkupDomain.ent">
%xmlmarkup-d-dec;
<!-- ================================================= -->
<!-- DOMAIN EXTENSIONS -->
<!-- ================================================= -->
<!ENTITY % keyword "keyword | %xmlmarkup-d-keyword;">
<!-- ================================================= -->
<!-- DOMAIN EXTENSIONS -->
<!-- ================================================= -->
<!ENTITY included-domains "&ui-d-att; &hi-d-att; &pr-datt; &sw-d-att; &ut-d-att; &indexing-d-att; &xmlmarkup-d-att;">
<!-- ================================================= -->
<!-- DOMAIN ELEMENT INTEGRATION -->
<!-- ================================================= -->
<!ENTITY % xmlmarkup-d-def SYSTEM "xmlmarkup.mod">
%xmlmarkup-d-def;Customizing XSLT stylesheets
The example adapts XSLT stylesheets producing XHTML files to process the specialized elements <xmlelement>, <xmlattribute>, <textentity> and <parameterentity> from the previous section.
The toolkit’s xsl directory holds the output-controlling stylesheets. XHTML production uses the dita2xhtml.xsl file.
A new stylesheet defining templates for the specialized elements imports the dita2xhtml.xsl file, adding new rules to existing processing.
Follow these steps:
Create a stylesheet importing the
dita2xhtml.xslfile.Define templates producing the desired specialized-element output.
If needed, create a CSS to format the transformed XHTML elements.
Here, all specialized elements should use the HTML element <code>. For the element <xmlelement>, add an opening angle bracket (<) before content and a closing angle bracket (>) after it. For the element <textentity>, add an ampersand (&) before content and a semicolon (;) after it. For the element <parameterentity>, add a percent sign (%) before content and a semicolon (;) after it.
No CSS classes are generated, so no CSS is defined below.
Create the stylesheet as follows:
Create this empty stylesheet, named
xmlmark-up2html.xsl.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [
!ENTITY gt ">">
<!ENTITY lt "<">
<!ENTITY rbl " ">
<!ENTITY nbsp " ">
<!ENTITY quot """>
<!ENTITY copyr "©">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="toolkitDir" select="'file:///c:/ditaot14/'"/>
<xsl:import href="{$toolkitDir}xsl/dita2xhtml.xsl"/>
</xsl:stylesheet>Its declaration gives the toolkit installation path, here
c:/ditaot14.
Save it outside the toolkit installation directory.
Create the XSLT template for processing the element
<xmlelement>as follows:
<xsl:template match="*[contains(@class, ' xmlmarkup-d/xmlelement ')]" priority="10">
<code>
<xsl:text><</xsl:text>
<xsl:apply-templates/>
<xsl:text>></xsl:text>
</code>
</xsl:template>Create the template processing the element
<xmlattribute>as follows:
<xsl:template match="*[contains(@class, ' xmlmarkup-d/xmlattribute ')]" priority="10">
<code>
<xsl:apply-templates/>
</code>
</xsl:template>Create the template processing the element
<textentity>as follows:
<xsl:template match="*[contains(@class, ' xmlmarkup-d/textentity ')]" priority="10">
<code>
<xsl:text>&</xsl:text>
<xsl:apply-templates/>
<xsl:text>;</xsl:text>
</code>
</xsl:template>Create the template processing the element
<parameterentity>as follows:
<xsl:template match="*[contains(@class, ' xmlmarkup-d/parameterentity ')]" priority="10">
<code>
<xsl:text>%</xsl:text>
<xsl:apply-templates/>
<xsl:text>;</xsl:text>
</code>
</xsl:template>The stylesheet
xmlmarkup2html.xslnow looks as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet [
!ENTITY gt ">">
<!ENTITY lt "<">
<!ENTITY rbl " ">
<!ENTITY nbsp " ">
<!ENTITY quot """>
<!ENTITY copyr "©">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="toolkitDir" select="'file:///c:/ditaot14/'"/>
<xsl:import href="{$toolkitDir}xsl/dita2xhtml.xsl"/>
<xsl:template match="*[contains(@class, ' xmlmarkup-d/xmlelement ')]" priority="10">
<code>
<xsl:text><</xsl:text>
<xsl:apply-templates/>
<xsl:text>></xsl:text>
</code>
</xsl:template>
<xsl:template match="*[contains(@class, ' xmlmarkup-d/xmlattribute ')]" priority="10">
<code>
<xsl:apply-templates/>
</code>
</xsl:template>
<xsl:template match="*[contains(@class, ' xmlmarkup-d/textentity ')]" priority="10">
<code>
<xsl:text>&</xsl:text>
<xsl:apply-templates/>
<xsl:text>;</xsl:text>
</code>
</xsl:template>
</xsl:stylesheet>
<xsl:template match="*[contains(@class, ' xmlmarkup-d/parameterentity')]" priority="10">
<code>
<xsl:text>%</xsl:text>
<xsl:apply-templates/>
<xsl:text>;</xsl:text>
</code>
</xsl:template>Test it by creating an XML file with the previous section’s domain_concepts.dtd file and using the new stylesheet for XHTML production. Further information is provided in ANT.
Copyright © 2008 XLcontent Verlag
You may print the online version for your private use.
Otherwise, this chapter from “DITA - Der neue Standard für Technische Dokumentation” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
XLcontent Verlag, Pflegerstraße 40, 81247 München