6 October 2012



I was looking for a solution for being able to indent XML plus use HTML5. According to Content with Style, there are some problems with XSLT and HTML 5.

I was able to create an HTML 5 Doctype with the following output instruction:

    indent="yes" />

Unfortunately, there is no indenting. It seems method="html" defaults to returns, but no indenting. But using method="xml" does output with indenting, however, there is an empty attribute string for the missing doctype-system attribute.

Nick Dunn advocated the polyglot compatible HTML5 doctype. This approach would output the doctype legacy string, as advocated by the W3C for legacy systems.

But, there were problems with this approach:

We’ve just hit a snag where we needed to output XML (XHTML) so that we could include Facebook namespaces (which didn’t work when the output type was html). The last resort is an HTML string parsing hack.

Nick came up with the HTML5 Doctype extension as a hack to override the output of the XSLT processor to replace the XHTML doctype with an HTML5 doctype. The hack was deemed folly and Nick was happy to hand over the responsibility to maintain the extension to myself.

I made some modifications to Nick's original code to fix some performance and output issues. I am using the approach that I originally described in the XSLT and HTML5 thread, where I split the output into two parts and only parse the first part (currently set to the first 15 lines) and then join them back together again.

So, I am officially releasing the extension on the Symphony site. By the way, Michael Eichelsdörfer has tested it and finds that it performs very well.


Enable this extension and every page will be processed to test whether the output contains the XHTML doctype strings. If these strings are found within the first 15 lines of the document, they will be replaced with the HTML5 doctype strings. Use the following output element in your master XSL stylesheet.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"

<xsl:output method="xml"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    indent="yes" />

<xsl:template match="/">
    <h1><xsl:value-of select="$website-name" /></h1>


We assume that the first four lines of the XSLT-generated XHTML document will look like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" lang="en" xml:lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

The extension will preserve attributes applied to the html element, such as lang or class attributes and will replace the meta element to set the content type and character set with the minimalist HTML5 version.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />

By setting the output to XHTML with the indent attribute set to yes, the output will preserve indenting and properly close elements, whether they are self-closing elements or empty elements.


Discuss this Extension


2.7.10 Unsure
2.7.9 Unsure
2.7.8 Unsure
2.7.7 Unsure
2.7.6 Unsure
2.7.5 Unsure
2.7.4 Unsure
2.7.3 Unsure
2.7.2 Unsure
2.7.1 Unsure
2.7.0 Unsure
2.6.11 Unsure
2.6.10 Unsure
2.6.9 Unsure
2.6.8 Unsure
2.6.7 Unsure
2.6.6 Unsure
2.6.5 Unsure
2.6.4 Unsure
2.5.4 Unsure

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details