How To Serve XHTML to Internet Explorer 6 And 7 as XML Using Content Negotiation


/ Published in: ASP
Save to your folder(s)

Serve your xhtml pages correctly with this script and xsl file. Most websites serve their xhtml pages as text and not xml to Internet Explorer. With this it will serve to IE as xml. Your sites will be more valid because they will validate against the xml validator rather than the html validator.


Copy this code and paste it in your HTML
  1. <%
  2. If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 Then
  3. Response.ContentType = "application/xhtml+xml"
  4. Else
  5. Response.ContentType = "application/xml"
  6. End If
  7. Response.Charset = "utf-8"
  8. %>
  9. <?xml-stylesheet type="text/xsl" href="xhtml.xsl"?>
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  11.  
  12. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  13. <head>
  14. <title>XHTML</title>
  15. </head>
  16.  
  17. <body>
  18.  
  19. <!--
  20. Contents of xhtml.xsl file
  21.  
  22. <stylesheet version="1.0"
  23. xmlns="http://www.w3.org/1999/XSL/Transform">
  24. <template match="/">
  25. <copy-of select="."/>
  26. </template>
  27. </stylesheet>
  28. -->
  29.  
  30.  
  31. </body>
  32. </html>

URL: http://www.nealgrosskopf.com/tech/thread.asp?pid=1

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.