Stylus Studio XML Editor

Table of contents

Appendices

6 XHTML Output Method

XHTML Output Method

The xhtml output method serializes the instance of the data model as XML, using the HTML compatibility guidelines defined in the XHTML specification.

It is entirely the responsibility of the person or process that creates the instance of the data model to ensure that the instance of the data model conforms to the [XHTML10] or [XHTML11] specification. It is not an error if the instance of the data model is invalid XHTML. Equally, it is entirely under the control of the person or process that creates the instance of the data model whether the output conforms to XHTML Strict, XHTML Transitional, XHTML Frameset, or XHTML Basic.

The serialization of the instance of the data model follows the same rules as for the xml output method, with the exceptions noted below. These differences are based on the HTML compatibility guidelines published in Appendix C of [XHTML10], which are designed to ensure that as far as possible, XHTML is rendered correctly on user agents designed originally to handle HTML.

  • Given an empty instance of an XHTML element whose content model is not EMPTY (for example, an empty title or paragraph) the serializer SHOULD MUST NOT use the minimized form. That is, it SHOULD MUST output <p></p> and not <p />.

  • Given an XHTML element whose content model is EMPTY, the serializer SHOULD MUST use the minimized tag syntax, for example <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents. The serializer SHOULD MUST include a space before the trailing />, e.g. <br />, <hr /> and <img src="karen.jpg"  alt="Karen" />.

  • The serializer SHOULD avoid outputting line breaks and multiple whitespace characters within attribute values. These are handled inconsistently by user agents.

  • The serializer SHOULD avoid use of MUST NOT use the entity reference &apos; which, although legal in XML and therefore in XHTML, is not defined in HTML and is not recognized by all HTML user agents.

  • The serializer SHOULD output namespace declarations in a way that is consistent with the requirements of the XHTML DTD if this is possible. The DTD requires the declaration xmlns="http://www.w3.org/1999/xhtml" to appear on the html element, and only on the html element. The serializer MUST output namespace declarations that are consistent with the namespace nodes present in the result tree, but it SHOULD avoid outputting redundant namespace declarations on elements where the DTD would make them invalid.

    NOTE: 

    addCWhere the process used to construct the input instance of the data model does not provide complete control over the prefix used for an element name in the instance of the data model or control of whether the element is in the default namespace (for instance, the XSLT namespace fixup process), implementors are encouraged to provide means or endeavor to preserve the obvious intent of a user to place the html element in in the default namespace, wherever possible. For example, implementors of XSLT processors are encouraged to place the html element that results from a literal result element like the following in the default namespace:

    <html xmlns="http://www.w3.org/1999/xhtml"> ... </html>

    delCAlthough the specification of the namespace fixup process provides no guarantees about the namespace prefixes that are allocated, implementors are encouraged to ensure that where possible, writing the literal result element <html xmlns="http://www.w3.org/1999/xhtml"> ... </html> places the resulting html element in the default namespace.

  • If the instance of the data model includes a head element in the XHTML namespace, then unless and the include-content-type parameter has the value "no" yes, the xhtml output method MUST add a meta element immediately after the start-tag of the head element specifying the character encoding actually used.

    For example,

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP"/>
    ...

    The content type SHOULD be set to the value given for the media-type parameter; the default value for XHTML is text/html. The value application/xhtml+xml, registered in [RFC3236], MAY also be used.

    addCIf the instance of the data model includes a head element that has a meta element child, the processor serializer SHOULD replace any content attribute of the meta element, or add such an attribute, with the value as described above, rather than output a new meta element.

  • Unless If the escape-uri-attributes parameter has the value no yes, the xhtml output method SHOULD MUST escape non-ASCII characters in URI attribute values using the method defined by Section 5.4 of [XLINK], except that relative URIs MUST NOT be absolutized. RECOMMENDED in Section 2.4.1 of [RFC2396].

NOTE: 

This escaping is deliberately confined to non-ASCII characters, because escaping of ASCII characters is not always appropriate, for example when URIs or URI fragments are interpreted locally by the HTML user agent. Even in the case of non-ASCII characters, escaping can sometimes cause problems. More precise control of URI escaping is therefore available by setting escape-uri-attributes to no, and controlling the escaping of URIs by means of the fn:escape-uri function defined in [FANDO].

NOTE: 

As with the XML output method, the XHTML output method outputs an XML declaration unless it is suppressed using the omit-xml-declaration parameter. Appendix C.1 of [XHTML10] provides advice on the consequences of including, or omitting, the XML declaration.

NOTE: 

addEAppendix C of [XHTML10] describes a number of compatibility guidelines for users of XHTML who wish to render their XHTML documents with HTML user agents. In some cases, such as the guideline on the form empty elements SHOULD take, only the serialization process itself has the ability to follow the guideline. In such cases, those guidelines are reflected in the requirements on the processor serializer described above.

addEIn all other cases, the guidelines can be adhered to by the instance of the data model that is input to the serialization process. The guideline on the use of whitespace characters in attribute values is one such example. It is the responsibility of the person or process that creates the instance of the data model that is input to the serialization process to ensure it is created in a way that is consistent with the guidelines. No serialization error results if the input instance of the data model does not adhere to the guidelines.