<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html> <head> <this-is section="extensions" page="instructions" subpage="doctype"/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: saxon:doctype</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: saxon:doctype"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>saxon:doctype</h1> <p>The <code>saxon:doctype</code> 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.</p> <p>The <code>saxon:doctype</code> instruction takes no attributes. 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.</p> <p>If this element is present the <code>doctype-system</code> and <code>doctype-public</code> attributes of <code>xsl:output</code> should not be present. Also, the <code>standalone</code> attribute of <code>xsl:output</code> should not be used. This is because the DOCTYPE declaration generated by <code>saxon:doctype</code> 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 <code>standalone</code> with such documents is prohibited by the W3C serialization specification.</p> <p>The generated XML document uses the following elements, where the namespace prefix "dtd" is used for the namespace URI "http://saxon.sf.net/dtd":</p> <table> <tr> <td content="para"> <p>dtd:doctype</p> </td> <td content="para"> <p>Represents the document type declaration. This is always the top-level element. The element may contain dtd:element, dtd:attlist, dtd:entity, and dtd:notation elements. It may have the following attributes:<br/> <b>name</b> (mandatory) The name of the document type<br/> <b>system</b> The system ID<br/> <b>public</b> The public ID </p> </td> </tr> <tr> <td content="para"> <p>dtd:element</p> </td> <td content="para"> <p>Represents an element type declaration. This is always a child of dtd:doctype. The element is always empty. It may have the following attributes:<br/> <b>name</b> (mandatory) The name of the element type<br/> <b>content</b> (mandatory) The content model, exactly as it appears in a DTD, for example content="(#PCDATA)" or content="( a | b | c)*"<br/> </p> </td> </tr> <tr> <td content="para"> <p>dtd:attlist</p> </td> <td content="para"> <p>Represents an attribute list declaration. This is always a child of dtd:doctype. The element will generally have one or more dtd:attribute children. It may have the following attributes:<br/> <b>element</b> (mandatory) The name of the element type<br/> </p> </td> </tr> <tr> <td content="para"> <p>dtd:attribute</p> </td> <td content="para"> <p>Represents an attribute declaration within an attribute list. This is always a child of dtd:attlist. The element will always be empty. It may have the following attributes:<br/> <b>name</b> (mandatory) The name of the attribute<br/> <b>type</b> (mandatory) The type of the attribute, exactly as it appears in a DTD, for example type="ID" or type="( red | green | blue)"<br/> <b>value</b> (mandatory) The default value of the attribute, exactly as it appears in a DTD, for example value="#REQUIRED" or value="#FIXED 'blue'"<br/> </p> </td> </tr> <tr> <td content="para"> <p>dtd:entity</p> </td> <td content="para"> <p>Represents an entity declaration. This is always a child of dtd:doctype. 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. The xsl:entity element may have the following attributes:<br/> <b>name</b> (mandatory) The name of the entity<br/> <b>system</b> The system identifier<br/> <b>public</b> The public identifier<br/> <b>parameter</b> Set to "yes" for a parameter entity<br/> <b>notation</b> The name of a notation, for an unparsed entity<br/> </p> </td> </tr> <tr> <td content="para"> <p>dtd:notation</p> </td> <td content="para"> <p>Represents a notation declaration. This is always a child of dtd:doctype. The element will always be empty. It may have the following attributes:<br/> <b>name</b> (mandatory) The name of the notation<br/> <b>system</b> The system identifier<br/> <b>public</b> The public identifier<br/> </p> </td> </tr> </table> <p>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.</p> <p>Example:</p> <div class="codeblock" style="border: solid thin; background-color: #B1CCC7; padding: 2px"> <pre> <code> <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 &gt; 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="D:\ent\ISOEntities" parameter="yes"> <xsl:text>%ISOEntities;</xsl:text> </dtd:doctype> </saxon:doctype> <xsl:apply-templates/> </xsl:template></code> </pre> </div> <p>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 <code>xsl:value-of</code> and <code>xsl:call-template</code>. It is also possible to use <code>xsl:text</code> 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.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="entity-ref.xml">Next</a></p> </td> </tr> </table> </body> </html>