Set Html5 Doctype With Xslt

Set HTML5 doctype with XSLT

I think this is currently only supported by writing the doctype out as text:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes" />

<xsl:template match="/">
<xsl:text disable-output-escaping='yes'><!DOCTYPE html></xsl:text>
<html>
</html>
</xsl:template>

</xsl:stylesheet>

This will produce the following output:

<!DOCTYPE html>
<html>
</html>

How to output !DOCTYPE html with XSLT

If you want absolutely the contracted form, your only choice is the disable-output-escaping of xsl:text as linked in the comments above. I think this is a bit dirty, and more, you have to indicate it within a template:

<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>
</xsl:template>

Alternative cleaner solution, W3C defines for HTML5 a specific DOCTYPE legacy string that can be used by HTML generators which can't display the doctype in the shorter format. So, to stay with pure XSLT you can use:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" doctype-system="about:legacy-compat" />

<xsl:template match="/">
<html>
<head>
<meta charset="utf-8" />
<title>Sample Corporation #1</title>
</head>
<body>
Hello this is a test<br />
Goodbye!
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Getting XSLT to render an HTML5 doctype in Firefox

There is a "proper" (non-hacky) way of rendering HTML5 with XSLT.

<xsl:output
method="xml"
doctype-system="about:legacy-compat"
encoding="UTF-8"
indent="yes" />

xslt output doctype before comments

Saxon is right, the specifications are clear: when serializing the result document the doctype declaration must be put immediately before the first element. This is specified in both XSLT 1.0 and XSLT 2.0:

If the doctype-system attribute is specified, the xml output method should output a document type declaration immediately before the first element.

To solve this you can add manually the doctype declaration in your document, using the xsl:text element with the disable-output-escaping attribute set to yes. For example you can output a standard HTML5 doctype, without any public identifier, which would be otherwise impossible to do in XSLT.

<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>

XSLT Refuses to write DOCTYPE declaration

The most likely explanation is that the stylesheet output is not being serialized using the Saxon serializer. For example, you might be writing the output to a DOM, and then using the DOM's serializer to produce the lexical XML.

That's just a guess, however - you haven't provided any information about how the transformation is being run.

error in doctype

The W3C HTML 5 Reference recommends using doctype-system="about:legacy-compat":

For compatibility with legacy producers of HTML — that is, software
that outputs HTML documents — an alternative DOCTYPE is available for
use by systems that are unable to output the DOCTYPE given above. This
limitation occurs in software that expects a DOCTYPE to include either
a PUBLIC or SYSTEM identifier, and is unable to omit them. The
canonical form of this DOCTYPE is as follows:

<!DOCTYPE html SYSTEM "about:legacy-compat">

You can achieve this with any XSLT processor with the following:

<xsl:output method="html" doctype-system="about:legacy-compat" />

It will generate:

<!DOCTYPE HTML SYSTEM "about:legacy-compat">

Setting doctype for XDV theme

See http://diazo.org/advanced.html?highlight=doctype#doctypes for how to do this in Diazo. I assume this also worked in XDV.

** EDIT: the change the links structure..
the current link is Diazo typeDoc



Related Topics



Leave a reply



Submit