saxon:doctype
The saxon:doctype
instruction is used to insert a document type declaration
into the current output file. It should be instantiated before the first element in the
output file is written. It must be used only when writing a final result tree (not a
temporary tree) and only when writing text nodes. The reason for these restrictions is
that saxon:doctype
writes directly to the serialized output stream
(internally it uses disable-output-escaping to achieve this). It is not possible to
represent a doctype declaration as a node on a temporary tree.
Category: declaration
Content:
sequence-constructor
Permitted parent elements:
xsl:stylesheet
; xsl:transform
Element has no attributes
Details
The content of the element is a template-body that is instantiated to create an XML document that represents the DTD to be generated; this XML document is then serialized using a special output method that produces DTD syntax rather than XML syntax.
If this element is present the doctype-system
and
doctype-public
attributes of xsl:output should not be present. Also, the
standalone
attribute of xsl:output
should not be used. This is
because the doctype declaration generated by saxon:doctype
is output as a
text node using disable-output-escaping, and thus appears to the serializer as a document
that is not well-formed; the use of standalone
with such documents is
prohibited by the W3C serialization specification.
The generated XML document uses the following elements, where the namespace prefix "dtd"
is used for the namespace URI http://saxon.sf.net/dtd
:
dtd:doctype
|
Represents the document type declaration. Category: declaration Content: dtd:element* ; dtd:attlist* ; dtd:entity* ;
dtd:notation*
Permitted parent elements: xsl:stylesheet ; xsl:transform | ||||||||||
Attributes: |
|
||||||||||
dtd:element
|
Represents an element type declaration. Category: declaration Content: none Permitted parent elements: dtd:doctype
| ||||||||||
Attributes: |
|
||||||||||
dtd:attlist
|
Represents an attribute list declaration. Category: declaration Content: dtd:attribute+
Permitted parent elements: dtd:doctype
| ||||||||||
Attributes: |
|
||||||||||
dtd:attribute
|
Represents an attribute declaration within an attribute list. Category: declaration Content: none Permitted parent elements: dtd:attlist
| ||||||||||
Attributes: |
|
||||||||||
dtd:entity
|
Represents an entity declaration. The element may be empty, or it may have content.
The content is a template body, which is instantiated to define the value of an
internal parsed entity. Note that this value includes the delimiting quotes. Category: declaration Content: sequence-constructor Permitted parent elements: dtd:doctype
| ||||||||||
Attributes: |
|
||||||||||
dtd:notation
|
Represents a notation declaration. Category: declaration Content: none Permitted parent elements: dtd:doctype
| ||||||||||
Attributes: |
|
Note that Saxon will perform only minimal validation on the DTD being generated; it will output the components requested but will not check that this generates well-formed XML, let alone that the output document instance is valid according to this DTD.
Examples
<xsl:template match="/"> <saxon:doctype xsl:extension-element-prefixes="saxon"> <dtd:doctype name="booklist" xmlns:dtd="http://saxon.sf.net/dtd" xsl:exclude-result-prefixes="dtd"> <dtd:element name="booklist" content="(book)*"/> <dtd:element name="book" content="EMPTY"/> <dtd:attlist element="book"> <dtd:attribute name="isbn" type="ID" value="#REQUIRED"/> <dtd:attribute name="title" type="CDATA" value="#IMPLIED"/> </dtd:attlist> <dtd:entity name="blurb">'A <i>cool</i> book with > 200 pictures!'</dtd:entity> <dtd:entity name="cover" system="cover.gif" notation="GIF"/> <dtd:notation name="GIF" system="http://gif.org/"/> <dtd:entity name="ISOEntities" public="ISO 8879-1986//ENTITIES ISO Character Entities 20030531//EN//XML" system="file:///D:/ent/ISOEntities" parameter="yes"> <xsl:text>%ISOEntities;</xsl:text> </dtd:doctype> </saxon:doctype> <xsl:apply-templates/> </xsl:template>Although not shown in this example, there is nothing to stop the DTD being generated as
the output of a transformation, using instructions such as xsl:value-of
and
xsl:call-template
. It is also possible to use xsl:text
to
output DTD constructs not covered by this syntax, for example conditional sections and
references to parameter entities. Such text nodes will always be output with escaping
disabled.