Content Negotiation
Content Negotiation: Setting The Media Type For Web Pages
XHTML 1.1 should be served as XML to Web browsers that support the application/xhtml+xml
media type. Most modern browsers such as Firefox, Opera and Safari do support the application/xhtml+xml
media type, but Internet Explorer is lagging behind the times. The IE development team has indicated that they plan to support this media type in the future, but until they do, xstandard.com will serve XHTML 1.0 Strict as HTML to browsers such as IE, using a technique called "content negotiation".
You can implement content negotiation for your own site if your Web site uses server-side scripting languages such as PHP, ASP, etc. Below are examples of how to set this up in different scripting languages. If you adopt this strategy, rest assured that your Web site continues to be XHTML 1.1 compliant. You can also continue to display the XHTML 1.1 compliance button that tells visitors that you have taken care to create an inter-operable Web site.
Setting The Media Type
PHP
$accept = $_SERVER["HTTP_ACCEPT"];
$ua = $_SERVER["HTTP_USER_AGENT"];
if (isset($accept) && isset($ua)) {
if (stristr($accept, "application/xhtml+xml") || stristr($ua, "W3C_Validator")) {
header("Content-Type: application/xhtml+xml");
}
}
Active Server Pages
Dim strAccept, strUA
strAccept = Request.ServerVariables("HTTP_ACCEPT").Item
strUA = Request.ServerVariables("HTTP_USER_AGENT").Item
If InStr(1, strAccept, "application/xhtml+xml") > 0 Or InStr(1, strUA, "W3C_Validator") > 0 Then
Response.ContentType = "application/xhtml+xml"
End If
C# In ASP.NET
string accept = Request.ServerVariables["HTTP_ACCEPT"];
string ua = Request.ServerVariables["HTTP_USER_AGENT"];
if (accept != null && ua != null) {
if (accept.IndexOf("application/xhtml+xml") >=0 || ua.IndexOf("W3C_Validator") >= 0) {
Response.ContentType = "application/xhtml+xml";
}
}
Declaration
You should apply the same principle and change the declaration to indicate you are serving XHTML 1.0 Strict:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
... instead of XHTML 1.1:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
CSS
When serving up XHTML 1.1, you can put the reference to CSS in a processing instruction. For example:
<?xml-stylesheet href="my.css" type="text/css" media="screen" title="My CSS"?>
...instead of in the style
element. For example:
<style type="text/css">@import url('my.css');</style>