22nd July, 2008

Use the correct XHTML doctype for your templates.

If you're working with XSL as a templating system, you'll want it to include the correct DTD.

The xsl:output tag has some options you need to configure correctly. At the top of your XSL file add

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
    version="string"
    encoding="UTF-8"
    omit-xml-declaration="yes"
    indent="yes"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />

Note: it is a closed tag. You need to omit-xml-declaration as the DOCTYPE must be the very first thing the browser sees.

Where you add the start HTML tag add the following:

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

You might want to use method="html" since "xml" will close any tags without content. This will break any empty <textarea> elements, since it is not a self-closing element.

Your pages should now validate correctly.

 

The opinions expressed here are my own and not those of my employer.