Pierre-Henri Lavigne wrote:
Regards to http://www.w3.org/MarkUp/2004/xhtml-faq#ie I just discovered,
I was just wondering if we could use :
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
You need to check the q value.
e.g. If a browser sends this:
Accept: text/html;application/xhtml+xml;q=0.5
text/html is preferred over application/xhtml+xml.
header("Content-Type: application/xhtml+xml; charset=UTF-8");
You don't need to include the charset parameter in this header for XML
MIME types (this does not apply to text/html). XML is designed as a
self describing format and does not need the information to be there.
Although, it does little harm by including it. There is, however, a
mostly theoretical issue of the document being transcoded by an
intermediate server, which wouldn't update the XML declaration.
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n");
No browser actually supports XHTML 1.1 properly. There are some small
but significant differences from XHTML 1.0, which makes XHTML 1.1 useless.
Either use XHTML 1.0, or omit the DOCTYPE completely. There is no
DOCTYPE sniffing for XML, and so the DOCTYPE only serves 2 purposes.
Validation and named entity references. For entity references to work
(e.g. ©), it actually requires a validating parser, although
$contentType="application/xhtml+xml; charset=utf-8";
} else {
header("Content-Type: text/html; charset=UTF-8");
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
In this case, the document is being served as text/html, and so it *is*
HTML, not XHTML. Do not include the XML declaration. It triggers
quirks mode in IE6 and earlier.
printf("<?xml-stylesheet type=\"text/xsl\" href=\"copy.xsl\" ?>\n");
That is a processing instruction for XML. It does not work in HTML!
But assuming you are intending that XSL stylesheet to be applied by IE,
like in the FAQ entry you cited, the document needs to be served with an
XML MIME type that is recognised by IE, such as application/xml
(preferred) or text/xml (not recommended). copy.xsl also needs to be
served as text/xsl.
However, DON'T DO THAT! Applying that XSLT transformation is a massive
performance hit for IE. Depending on the size of the document, it can
take several seconds to transform before rendering anything, which is a
bad user experience.
All it does is effectively change all the unrecognised XML elements in
the DOM into recognised HTML elements, and so you gain no benefit over
using ordinary HTML.
printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
Why did you choose XHTML 1.0 here, but XHTML 1.1 earlier? IE fails to
recognise either one of them, and so it makes absolutely no difference,
even if you are apply the XSLT.
The rest of my comments ignore the intended XSL transformation and
assume this is being served as text/html. In which case, this document
is HTML, not XHTML. Use either an HTML 4.01 Strict DOCTYPE or an HTML5
doctype, which is simply:
<!DOCTYPE html>
The DOCTYPE is only really needed in HTML for triggering standards mode,
though if you wish to validate using an SGML parser (like the W3C
validator) then you'd need to use the HTML4 DOCTYPE. (There are
alternatives for checking the conformance of an HTML5 document).
$contentType="text/html; charset=utf-8";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
That's correct for XHTML, but incorrect for HTML. HTML should use the
following instead:
<html lang="en">
<head>
<title>Hehe</title>
<meta http-equiv="Content-Language" content="en-us" />
That meta element is completely useless. If you wish to specify the
Content-Language, do so using an HTTP header. However, you should do
some research on the actual purpose of that header and determine if you
really need to use it at all.
<meta http-equiv="Content-Type" content="<?php printf($contentType);?>" />
You do not need that at all, although you may wish to include it in HTML
(not XHTML) so that users who save the document will still have
encoding information.
For XHTML, it outputs:
<meta http-equiv="Content-Type" content="application/xhtml+xml;
charset=utf-8" />
This is completely useless. The meta element is ignored in XHTML and
changing the MIME type makes no difference. Browsers do not pay
attention to the MIME type declared there because they need to have
already decided which parser to use before they begin parsing. They
also pay no attention to the charset parameter either because XML rules
apply for determining the character encoding, which has already been
determined at this point.
For HTML, it outputs:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The meta element is only somewhat useful for HTML. When no other
encoding information is available, only the charset parameter is
actually used. However, in this case, you've already declared the
encoding in the HTTP headers, where it belongs.
If you wish to include this meta element for HTML, you do not need to
include the trailing slash because that is XML syntax only. You would
also need to handle this issue elsewhere if you make use of any other
empty elements.
What do you think about ?
That depends what exactly you're referring to. If you're referring to
the XSLT recommended in the XHTML FAQ, I think it's a waste of effort
(see above).
If your referring to the MIME type switch, I also think it's a waste of
effort, though for different reasons. You gain little benefit by
maintaining the document as both HTML and XHTML. Also be aware of the
fact that current versions of Firefox and Mozilla cannot incrementally
render XHTML. This may not be a serious problem for small documents,
but as they get larger and take longer to download, it's really annoying
for the user because nothing is rendered until the whole document has
been downloaded and parsed.
Note that this bug has been fixed in very recent builds of the Mozilla
trunk (within the last few weeks), and I assume that fix will be in
Firefox 3.
I suppose if the trick works, everyone will use it.
No, most people don't use it, and nobody should use it, because it's
pointless.
--
Lachlan Hunt
http://lachy.id.au/
*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
*******************************************************************