Manage constraints on vocabularies
DITA adopters have long requested the ability to restrict element content without changing the semantics or processing expectations. As the number of specialized vocabularies increases, an increasing need to restrict the choices presented to writers is an inevitable consequence.
Because specialization adds branches to the type hierarchy, specialization is not an optimal solution for this request. Using specialization to implement restriction pads the type hierarchy with types that don't introduce new semantics.
Allow constraints on the content of elements provided by vocabularies.
Definition: A constraint eliminates some of the possible instances of the vocabularies assembled by a document type without changing the semantics of those vocabularies.
The availability of constraints has benefits for the type hierarchy. Designers can specialize with general elements and loose content models and rely on constraints to provide a more guided authoring experience. Such flexible vocabularies provide a better base for subsequent specialization.
For an earlier version of this proposal, please see:
http://www.oasis-open.org/committees/download.php/14936/Issue34.html
Constraints must allow the following kinds of restrictions:
A constraint should be able to simplify or enforce best practices for the element content. For instance, a constraint should be able to omit optional elements, restrict the range of occurrences for a position, turn a choice with more with one occurrence into a sequence, restrict the values of an attribute, remove an attribute, and so on.
The request to simplify the content model for the <section> element or block elements is common:
http://tech.groups.yahoo.com/group/dita-users/message/258
More formally, a content constraint imposes a restriction allowed under the rules of specialization without changing the semantics of the container element.
Also because vocabulary compatibility is established by module, domain extensions cannot replace a base element but can only add alternatives to the base element.
A constraint should be able to extend a base element with only some of the specialized elements provided by domain vocabularies. For example, a constrained domain might extend the <ph> element with the <b> and <i> elements from the highlight domain but not with the <sub>, <sup>, <tt>, or <u> elements.
In addition, a constraint should be able to replace the base element with the specialized domain elements. Effectively, such replacement makes the base element an abstract element in the context.
Here is a sample request for this capability:
http://tech.groups.yahoo.com/group/dita-users/message/524
DITA 1.1 allows document type shells to replace nested <topic> elements without providing a method by which processors can detect such restrictions. To formalize this practice, constraint support for replacement domains should also handle replacement of nested topics.
Beyond these specific requirements, the constraint capability must meet the following more general requirements:
The adopter performs the following actions:
The adopter could constrain different document type shells for other authoring populations and write common processing against the unconstrained document type.
Similarly, if blocks were relaxed to allow self nesting to enable specialization, constraints could preserve that restriction in the existing document type shells.
This proposal has the following impacts:
Constraints can be applied:
An element content model can be constrained only by one constraint module. However, different constraint modules can constrain different elements from the same vocabulary module. These wrappers can be nested in an XSD implementation or sequenced in a DTD implementation.
A document type with constraints allows a subset of the possible instances of a document type for the same vocabularies without constraints. To put it another way, all instances of the constrained document type are guaranteed to be valid instances of the unconstrained document type.
As a result, a constraint doesn't change basic or inherited content processing. The constrained instances remain valid instances of the element type, and the element retains the same semantics and class attribute declaration. In other words, a constraint never creates a new case for content processing.
For instance, a document type constrained to require the <shortdesc> element allows a subset of the possible instances of the unconstrained document type with an optional <shortdesc> element. Thus, the content processing for topic still works when topic is constrained to require a short description.
Currently, DITA document instances declare (by means of the domains attribute and the class attribute for the top element) the vocabularies available in its document type. A processor can examine these declarations to determine whether a document instance uses a subset of the vocabularies in another DITA document type and thus is compatible with that document type.
A constrained document type allows only a subset of the possible instances of the unconstrained document type. Thus, for a processor to determine whether a document instance is compatible with another document type, the document instance must declare any constraints on the document type.
For instance, an unconstrained task is compatible with an unconstrained topic because the task can be generalized to topic. If, however, the topic is constrained to require the <shortdesc> element, a document type with an unconstrained task is not compatible with the constrained document type because some instances of the task might not have a <shortdesc> element. If, however, the task document type has also been constrained to require the <shortdesc> element, it is compatible with the constrained topic document type.
As a result
Thus, these operations require the declaration of constraints:
No renaming of elements is needed to remove constraints.
The DITA architecture adds a new constraints attribute to declare the constraints applied to the content of elements to enable compatibility checking by processors. The constraints attribute provides a list of parenthetical expressions, each of which declares constraints on either an element's content model or on the global availability of an element.
1 constraint-declaration ::= '(' S? content-constraint | domain-constraint S? ')'
2 content-constraint ::= vocabularyModule '/' element S '=' (S constraintName)+
3 domain-constraint ::= '*' S? '=' S '-' (S element)+
Here is an example:
constraints="
(* = - ph tt)
(topic/topic = simpleTopic shortdescReq noRelLink)
(topic/section = simpleTopic)
(topic/example = simpleTopic)
(topic/task = simpleTask simpleTopic)
(topic/prereq = simpleTask simpleTopic)
(topic/context = simpleTask simpleTopic)
(topic/result = simpleTask simpleTopic)
(topic/postreq = simpleTask simpleTopic)"
The previous constraints attribute declared the following constraints:
In the same way that the designer bears the responsibility of implementing a specialized content model consistent with its base module, the designer also bears the responsibility of implementing a constrained content model consistent with a less constrained content model. In the example, if the shortdescReq constraints module becomes more restrictive than the simpleTopic constraints module, the maintainer of the simpleTopic constraints module must either enforce the same constraints or remove the declaration.
The following example declares that the base topic element has been replaced by a specialized topic element. The existing concept, reference, and task document types can add this declaration so conref processors can detect problems with conref to a task containing a base <topic> topic (for instance, from a ditabase document instance):
constraints="(* = - topic)"
Thus, to determine compatibility, the conref processor can check the constraints attribute to confirm:
A more sophisticated conref processor can perform a fine-grained check of the constraints on the referencing placeholder and the referenced content fragment.
The generalization transform preserves the constraints attribute during roundtripping respecialization by normalizing the attribute. A document instance can be converted from a constrained document type to a document type with a subset of the constraints merely by switching the binding of the document instance to the less restricted schema (which would also have a different constraints attribute declaration).
Similar to domains, the rootname for a constraints module has a required "Constraints" infix that doesn't appear in references to the constraints module. For instance, "simpleTopic" is the qualifier corresponding to the simpleTopicConstraint.xsd Schema module and the simpleTopicConstraint.mod DTD module.
The basic strategy for implementing constraints in schemas is as follows:
...
<xs:group name="hi-d-ph-nott">
<xs:choice>
<xs:element ref="b"/>
<xs:element ref="i"/>
<xs:element ref="sub"/>
<xs:element ref="sup"/>
<xs:element ref="u"/>
</xs:choice>
</xs:group>
...
...
<xs:redefine schemaLocation="topicMod.xsd">
<!-- constrain content and attributes of <topic> element -->
<xs:complexType name="topic.class">
<xs:complexContent>
<xs:restriction base="topic.class">
<xs:sequence>
<xs:group ref="title"/>
<xs:group ref="titlealts" minOccurs="0"/>
<!-- make required -->
<xs:choice>
<xs:group ref="shortdesc" />
<xs:group ref="abstract" />
</xs:choice>
<xs:group ref="prolog" minOccurs="0"/>
<xs:group ref="body" minOccurs="0"/>
<!-- remove <related-links> -->
<xs:group ref="topic-info-types" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
...
</xs:redefine>
...
...
<xs:include schemaLocation="highlightNott.xsd"/>
...
<xs:redefine schemaLocation="commonElementGrp.xsd">
<xs:group name="ph">
<!-- drop base <ph> as well as apply nott subset of highlight domain -->
<xs:choice>
<xs:group ref="hi-d-ph-nott"/>
</xs:choice>
</xs:group>
...
</xs:redefine>
<xs:redefine schemaLocation="simpleTopicConstraint.xsd">
<xs:complexType name="topic.class">
<xs:complexContent>
<xs:extension base="topic.class">
<xs:attribute name="constraints" type="xs:string" default="
(* = - ph tt)
(topic/topic = simpleTopic shortdescReq noRelLink)"/>
...
</xs:extension>
</xs:complexContent>
</xs:complexType>
...
</xs:redefine>
...
The basic strategy for implementing constraints in DTDs is as follows:
...
<!ENTITY % topic.content "((%title;), (%titlealts;)?, (%shortdesc;|%abstract;)?,
(%prolog;)?, (%body;)?, (%related-links;)?, (%topic-info-types;)*)">
<!ENTITY % topic.attributes
"id ID #REQUIRED
conref CDATA #IMPLIED
%select-atts;
%localization-atts;
outputclass CDATA #IMPLIED">
...
<!ELEMENT topic %topic.content;>
<!ATTLIST topic %topic.attributes;>
<!ATTLIST topic
%arch-atts;
domains CDATA "&included-domains;">
...
<!ENTITY % hi-d-ph-nott "b | u | i | sup | sub"> <!-- elements removed by all subset entities --> <!ENTITY hi-d-nott "tt">
<!ENTITY topic-constraints "(topic/topic = simpleTopic shortdescReq noRelLink)">
...
<!ENTITY % topic.content "((%title;), (%titlealts;)?, (%shortdesc;|%abstract;),
(%prolog;)?, (%body;)?, (%topic-info-types;)*)">
...
...
<!ENTITY % hi-d-nott SYSTEM "highlightNott.ent">
%hi-d-nott;
...
<!-- drop base <ph> as well as apply nott subset of highlight domain -->
<!ENTITY % ph "%hi-d-ph-nott;">
...
<!ENTITY % simpleTopic-constraint SYSTEM "simpleTopicConstraint.mod">
%simpleTopic-constraint;
...
<!ENTITY included-constraints "(* = - ph &hi-d-nott;)
&topic-constraints;">
...
<!ENTITY % topic-type SYSTEM "topic.mod">
%topic-type;
...
It would be quite useful for design flexibility to restrict a domain extension to a subset of the contexts where the base element can appear. For instance, because the <data> element appears in so many contexts, domain extension is essentially unusable for the <data> element. Yet, taken in isolation, the <data> element should provide a useful base for a plethora of reusable elements.
Here is a sample request for this capability:
http://www.oasis-open.org/apps/org/workgroup/dita/email/archives/200504/msg00011.html.
Because DITA 1.1 treats global attributes as domains, attributes that are specific to a set of elements can be treated as a special case of constraining a domain to a subset of the possible contexts for extension.
Implementing context-specific XSD groups or DTD entities, however, would impose an unsupportable burden on the designer.
To represent the business data, the adopter would like to make use of the UN/CEFACT CCTS (Core Component Technical Specification), which provides a standard vocabulary (adopted by UBL and OAGIS) for business data starting with atomic data like price and quantity and aggregating composite data structures like order contract and product item.
http://xml.coverpages.org/ni2007-04-20-a.html#excerpts
The adopter performs the following actions: