可能重复:
使用XSLT设置HTML5 doctype
我是xslt的新手,我正在尝试制作HTML 5文档.
<?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>
Run Code Online (Sandbox Code Playgroud)
和Firefox给了我错误
"XML Parsing Error: not well-formed
Location: file:///E:/XSLT-XML-Shema/shipping-transform.xsl
Line Number 6, Column 4: <!DOCTYPE html>
Run Code Online (Sandbox Code Playgroud)
如果它只是<html>它工作正常.我该如何解决这个问题?为什么会这样?
- 编辑 -
<?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" 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>
Run Code Online (Sandbox Code Playgroud)
Emi*_*ggi 24
如果你想绝对承包形式,你唯一的选择是disable-output-escaping的xsl:text,如上述评论链接.我认为这有点脏,而且,你必须在模板中指出它:
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
替代清理器解决方案,W3C为HTML5定义了一个特定的DOCTYPE遗留字符串,HTML生成器可以使用该字符串,它不能以较短的格式显示doctype.因此,要使用纯XSLT,您可以使用:
<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>
Run Code Online (Sandbox Code Playgroud)