I propose adding the following text to the RenderKit spec for
javax.faces.Outputjavaxfaces.Doctype (and thus <h:doctype>):
No relocation occurs with the output of this component. It is
rendered at whatever position in the view hierarchy it happens to be
encountered when traversing the view to render. Therefore, this
component must be located in the view hierarchy at the correct
location so that the final rendered markup has it in the proper place
with respect to the user agent that consumes the rendered markup. In
practice this means in front of the <html> or <h:html> element.
Furthermore, if multiple <h:doctype> components exist, all of them
will be rendered, which is not correct for any user agent.
If this component is present in a view, any DOCTYPE that would
otherwise have been rendered by virtue of being present in the VDL
page must be ignored.
I propose adding a new section to the facelets chapter in the spec prose
document (chapter 10 in the latest version), within the section "General
10.3.1.1 DOCTYPE and XML Declaration
When processing Facelet VDL files, the system must ensure that at most
one XML declaration and at most one DOCTYPE declaration appear in the
rendered markup, if and only if there is corresponding markup in the
Facelet VDL files for those elements. If multiple occurrences of XML
declaration and DOCTYPE declaration are encountered when processing
Facelet VDL files, the "outer-most" occurrence is the one that must be
rendered. If an XML declaration is present, it must be the very first
markup rendered, and it must precede any DOCTYPE declaration (if
present). The output of the XML and DOCTYPE declarations are subject
to the configuration options listed in the table titled "Valid
<process-as> values and their implications on the processing of
Facelet VDL files" in the appendix titled "JSF Metadata".