How to output <!DOCTYPE html> with XSLT [duplicate]
Possible Duplicate:
Set HTML5 doctype with XSLT
I'm new to xslt and I'm trying to produce an HTML 5 document.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!DOCTYPE html>
and Firefox gives me the error
"XML Parsing Error: not well-formed
Location: file:///E:/XSLT-XML-Shema/shipping-transform.xsl
Line Number 6, Column 4: <!DOCTYPE html>
If it's just <html>
it works fine. How do I fix this and why does it happen?
--EDIT--
<?xml version="1.0" enc开发者_高级运维oding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" doctype-system="about:legacy-compact" />
<xsl:template match="/">
<!DOCTYPE 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>
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>
精彩评论