16.1 XML Output Method
XML Output Method
The xml output method outputs the result tree as a
well-formed XML external general parsed entity. If the root node of
the result tree has a single element node child and no text node
children, then the entity should also be a well-formed XML document
entity. When the entity is referenced within a trivial XML document
wrapper like this
<!DOCTYPE doc [
<!ENTITY e SYSTEM "entity-URI">
]>
<doc>&e;</doc>
where entity-URI is a URI for the entity,
then the wrapper
document as a whole should be a well-formed XML document conforming to
the XML Namespaces Recommendation [XMLNAMES]. In
addition, the output should be such that if a new tree was constructed
by parsing the wrapper as an XML document as specified in [Data Model], and then removing the document element, making its
children instead be children of the root node, then the new tree would
be the same as the result tree, with the following possible
exceptions:
If the XSLT processor generated a document type declaration because
of the doctype-system attribute, then the above
requirements apply to the entity with the generated document type
declaration removed.
The version attribute specifies the version of XML to
be used for outputting the result tree. If the XSLT processor does
not support this version of XML, it should use a version of XML that
it does support. The version output in the XML declaration (if an XML
declaration is output) should correspond to the version of XML that
the processor used for outputting the result tree. The value of the
version attribute should match the VersionNum production of the XML
Recommendation [XML]. The default value is
1.0.
The encoding attribute specifies the preferred
encoding to use for outputting the result tree. XSLT processors are
required to respect values of UTF-8 and
UTF-16. For other values, if the XSLT processor does not
support the specified encoding it may signal an error; if it does not
signal an error it should use UTF-8 or
UTF-16 instead. The XSLT processor must not use an
encoding whose name does not match the EncName production of the XML
Recommendation [XML]. If no encoding
attribute is specified, then the XSLT processor should use either
UTF-8 or UTF-16. It is possible that the
result tree will contain a character that cannot be represented in the
encoding that the XSLT processor is using for output. In this case,
if the character occurs in a context where XML recognizes character
references (i.e. in the value of an attribute node or text node), then
the character should be output as a character reference; otherwise
(for example if the character occurs in the name of an element) the
XSLT processor should signal an error.
If the indent attribute has the value
yes, then the xml output method may output
whitespace in addition to the whitespace in the result tree (possibly
based on whitespace stripped from either the source document or the
stylesheet) in order to indent the result nicely; if the
indent attribute has the value no, it should
not output any additional whitespace. The default value is
no. The xml output method should use an
algorithm to output additional whitespace that ensures that the result
if whitespace were to be stripped from the output using the process
described in [Whitespace Stripping] with the set of
whitespace-preserving elements consisting of just
xsl:text would be the same when additional whitespace is
output as when additional whitespace is not output.
NOTE:
It is usually not safe to use indent="yes" with
document types that include element types with mixed content.
The cdata-section-elements attribute contains a
whitespace-separated list of QNames. Each QName is expanded into an
expanded-name using the namespace declarations in effect on the
xsl:output element in which the QName occurs; if there is a default
namespace, it is used for QNames
that do not have a prefix. The expansion is performed before the
merging of multiple xsl:output elements into a single
effective xsl:output element. If the expanded-name of the
parent of a text node is a member of the list, then the text node
should be output as a CDATA section. For example,
<xsl:output cdata-section-elements="example"/>
would cause a literal result element written in the stylesheet as
<example><foo></example>
or as
<example><![CDATA[<foo>]]></example>
to be output as
<example><![CDATA[<foo>]]></example>
If the text node contains the sequence of characters
]]>, then the currently open CDATA section should be
closed following the ]] and a new CDATA section opened
before the >. For example, a literal result element
written in the stylesheet as
<example>]]></example>
would be output as
<example><![CDATA[]]]]><![CDATA[>]]></example>
If the text node contains a character that is not representable in
the character encoding being used to output the result tree, then the
currently open CDATA section should be closed before the character,
the character should be output using a character reference or entity
reference, and a new CDATA section should be opened for any further
characters in the text node.
CDATA sections should not be used except for text nodes that the
cdata-section-elements attribute explicitly specifies
should be output using CDATA sections.
The xml output method should output an XML declaration
unless the omit-xml-declaration attribute has the value
yes. The XML declaration should include both version
information and an encoding declaration. If the
standalone attribute is specified, it should include a
standalone document declaration with the same value as the value as
the value of the standalone attribute. Otherwise, it
should not include a standalone document declaration; this ensures
that it is both a XML declaration (allowed at the beginning of a
document entity) and a text declaration (allowed at the beginning of
an external general parsed entity).
If the doctype-system attribute is specified, the
xml output method should output a document type
declaration immediately before the first element. The name following
<!DOCTYPE should be the name of the first element. If
doctype-public attribute is also specified, then the
xml output method should output PUBLIC
followed by the public identifier and then the system identifier;
otherwise, it should output SYSTEM followed by the system
identifier. The internal subset should be empty. The
doctype-public attribute should be ignored unless the
doctype-system attribute is specified.
The media-type attribute is applicable for the
xml output method. The default value for the
media-type attribute is text/xml.
|