document-type-declaration condition? local-declaration* action*
document-type-declaration is a rule that fires on the document type declaration (DTD), if any, of a
parsed input. As a region rule,
document-type-declaration fires on the whole of the DTD and must process either
#content. Both in the rule guard and in the body of the rule, the built-in shelf
can be used to access the DTD's name. In the body of the rule,
#doctype can be assigned to change the actual
document type of the input being processed.
The following SGML input defines element
a as the document type.
<!doctype a [ <!element a - - (#pcdata)> <!element b o o (a)> <!element c - - (#pcdata)> ]> <a>Hello, World!</a>
If we wanted to change this to
b to, for instance, perform additional processing, we could use a
document-type-declaration rule, as in the program below:
process do sgml-parse document scan #main-input output "%c" done document-type-declaration set #doctype to "b" suppress element #implied output "<%q>%c</%q>"
Execution of this program would yield the output
When changing the document type in this fashion, the transformation must result in a markup stream that
conforms to the validation rules in effect for the input. For instance, in the example SGML DTD above, element
b was declared as being omissible and its content model allowed for one instance of element
It could thus serve as a parent element for the element
a that appeared explicitly in the input, even
though it itself does not appear in the input. If, on the other hand, we had attempted to change the document type to
c, three validation errors would have been triggered:
cis not omissible, and therefore must be physically present in the document instance,
ccannot contain element
cis not omissible, and therefore must be physically present in the document instance.
Similarly, if we had attempted to change the document type to
d, a run-time error would have been
triggered, since there is no such element in the DTD.
document-type-declaration rule completes its execution before any
prolog-end rule is