Edit online

Controlled Attribute Values for your DITA Project

Read time: 4 minute(s)

Frequently when editing DITA content you will feel the need to enforce a controlled set of values when editing certain attributes. For example you may want to impose that the values for the @outputclass attribute on the element codeblock are either language-xml or language-css. This is useful in order to remind writers that any other value will not be interpreted by the build process in a significant manner.

Oxygen has a couple of easy ways in which controlled values can be imposed for certain attributes:
  1. You can edit the XML configuration file OXYGEN_INSTALL_DIR/frameworks/dita/resources/cc_value_config.xml and provide additional entries. In the case of our small example for providing controlled values for the @attribute the configuration file should contain an additional entry:
    <match elementName="codeblock" attributeName="outputclass">
     <items action="addIfEmpty">
      <item value="language-xml" annotation="XML Syntax Highlight"/>
      <item value="language-css" annotation="CSS Syntax Highlight"/>
    Besides providing a hard-coded list of values the content completion configuration file is flexible enough to allow calling an XSLT stylesheet which could retrieve those values from other sources (for example via HTTP from an Exist database).
  2. Provide those controlled values via a Subject Scheme Map (my favorite). Coming back to our example, you can create a small Subject Scheme map with the file name controlledValues.ditamap and the content:
    <!DOCTYPE subjectScheme PUBLIC "-//OASIS//DTD DITA Subject Scheme Map//EN""map.dtd"> 
                <navtitle>Provide controlled attributes</navtitle>
            <subjectdef keys="languageTypeKey">
                <subjectdef keys="language-xml">
                        <navtitle>XML Syntax Highlight</navtitle>
                <subjectdef keys="language-css">
                        <navtitle>CSS Syntax Highlight</navtitle>
            <elementdef name="codeblock"/>
            <attributedef name="outputclass"/>
            <subjectdef keyref="languageTypeKey"/>
    then you can refer to it from your main DITA Map like:
    <topicref href="controlledValues.ditamap" format="ditamap" type="subjectScheme"/>
  3. If the attributes on which you want to impose certain values are DITA profiling attributes, you can go to the Oxygen Preferences->Editor / Edit modes / Author / Profiling/Conditional Text page and define the set of allowed values for them.

The only problem with the first approach is the fact that validation will not impose those values and writers will not receive validation error messages if they set another value for the specific attribute. So you will probably need to add a Schematron check in order to signal errors when a certain attribute's value does not match the list of controlled attribute values. For both the second and third approaches, validation will warn the writers if certain attribute values do not match values in the controller values list.