Can custom attributes have default values in DITA specialization?
Yes, custom attributes can have default values in DITA specialization. This feature allows content creators to define a predefined value for a custom attribute that is automatically assigned to an element if the attribute is not explicitly specified. Default values provide consistency and reduce the need for repetitive attribute assignments.
Establishing a default value for a custom attribute involves creating a specialization schema, defining the custom attribute, and assigning a default value in that schema.
Create a Specialization Schema
Begin by creating a specialization schema that extends the base DITA schema and includes the definition of the custom attribute.
Define the Custom Attribute
Within the specialization schema, the custom attribute is defined as normal, being assigned a name, data type, and any constraints.
Assign a Default Value
To assign a default value to the custom attribute, the default attribute is used within the attribute definition. Set the default attribute to the desired default value.
Example
A DITA specialization schema for software documentation requires a custom attribute called @status for the <feature> element. The default value for @status should be “draft” unless explicitly specified.
<specialization>
<element name="feature">
<!-- Define a custom attribute with a default value -->
<attribute name="status" type="string" default="draft"/>
</element>
</specialization>
In this example, the @status attribute is defined with a default value of “draft.” If a <feature> element is used without explicitly specifying the @status attribute, it will automatically have the “draft” status by default.