如何输出<!DOCTYPE html>使用XSLT [英] How to output <!DOCTYPE html> with XSLT

查看:117
本文介绍了如何输出<!DOCTYPE html>使用XSLT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

使用XSLT设置HTML5文档类型

我是新手xslt和我正在尝试生成HTML 5文档。

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>

和Firefox给我错误

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>

如果它只是< html> 它工作正常。我该如何解决这个问题?为什么会这样?

If it's just <html> it works fine. How do I fix this and why does it happen?

- 编辑 -

<?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>


推荐答案

如果你想要绝对简约的表格,你唯一的选择是上面评论中链接的 disable-output-escaping xsl:text 。我认为这有点脏,而且你必须在模板中指出:

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">&lt;!DOCTYPE html&gt;</xsl:text>
</xsl:template>

替代清洁解决方案,W3C为HTML5定义了一个特定的DOCTYPE遗留字符串,可供HTML生成器使用无法以较短的格式显示doctype。因此,要使用纯XSLT,您可以使用:

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>

这篇关于如何输出&lt;!DOCTYPE html&gt;使用XSLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆