使用 XSLT 设置 HTML5 文档类型
如何通过 XSLT 将文件的文档类型干净设置为 HTML5 (在本例中使用 collective.xdv)
以下是我的 Google foo 能够找到的最好的:
<xsl:output
method="html"
doctype-public="XSLT-compat"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />
产生:
<!DOCTYPE html PUBLIC "XSLT-compat" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
我认为目前只能通过将文档类型写为文本来支持:
这将产生以下输出:
I think this is currently only supported by writing the doctype out as text:
This will produce the following output:
要使用简单的 HTML 文档类型
,您必须使用
disable-output-escaping
功能:
。但是,disable-output-escaping
是 XSLT 中的一个可选功能,因此您的 XSLT 引擎或序列化管道可能不支持它。因此,HTML5 提供了一种替代文档类型,以与不支持 HTML5 的 XSLT 版本(即所有当前存在的 XSLT 版本)以及具有相同问题的其他系统兼容。替代文档类型是
。要输出此文档类型,请在
xsl:output
元素上使用属性doctype-system="about:legacy-compat"
,无需使用 < code>doctype-public 属性根本没有。To use the simple HTML doctype
<!DOCTYPE html>
, you have to use thedisable-output-escaping
feature:<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>
. However,disable-output-escaping
is an optional feature in XSLT, so your XSLT engine or serialization pipeline might not support it.For this reason, HTML5 provides an alternative doctype for compatibility with HTML5-unaware XSLT versions (i.e. all the currently existing versions of XSLT) and other systems that have the same problem. The alternative doctype is
<!DOCTYPE html SYSTEM "about:legacy-compat">
. To output this doctype, use the attributedoctype-system="about:legacy-compat"
on thexsl:output
element without using adoctype-public
attribute at all.此输出
被修改为我对 http://ukchill.com/technology/generate-html5-using- 的修复xslt/
this outputs
this is modified as my fix to http://ukchill.com/technology/generating-html5-using-xslt/
使用 Saxon 9.4,您可以使用:
这会生成:
With Saxon 9.4 you can use:
This generates:
使用 doctype-system 而不是 doctype-public
Use doctype-system instead of doctype-public
如果您希望 XHTML 输出与 HTML5 一致,则必须使用 XHTML 1.0 Strict 作为文档类型,libxml2 的 xml 序列化程序具有由 XHTML 1.0 文档类型触发的特殊输出模式,可确保输出与 XHTML 兼容(例如
而不是
,而不是
< div>>
)。doctype-system="about:legacy-compat"
确实不会触发此兼容模式如果您对 html 输出感到满意,则设置
应该做正确的事情。然后,您可以使用<!DOCTYPE html>
设置文档类型,尽管这样需要在适当的地方安装管道,因为 XDV 尚不支持这一点。事实上,似乎
也没有真正帮助 - 这将导致
输出为。
You must use XHTML 1.0 Strict as the doctype if you want XHTML output consistent with HTML5, libxml2's xml serializer has a special output mode triggered by the XHTML 1.0 doctypes that ensures output is XHTML compatible, (e.g.
<br />
rather than<br/>
,<div></div>
rather than<div/>
).doctype-system="about:legacy-compat"
does not trigger this compatibility modeIf you are happy with html output, then setting
<xsl:output method="html">
should do the right thing. You can then set the doctype with<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>
, though this will need plumbing in at the appropriate place as XDV does not support this yet.In fact it seems
<xsl:output method="html"/>
does not really help either - this will result in<br/>
being output as<br></br>
.Jirka Kosek 的建议的变体,来自 高级 XDV 主题 Plone.org 似乎对我有用 集体.xdv。
This variation of Jirka Kosek's advice, via Advanced XDV theming on Plone.org seems to work for me in collective.xdv.
这是一条评论,但我没有足够的业力点将其放在正确的位置。叹。
不,您的 XSLT 处理器没有损坏,只是 XDV 添加了:
,因此当您添加第二个
时,前一个>doctype-public
不会被覆盖。请注意,XHTML 1.0 strict 被列为过时的允许文档类型字符串,因此使用此文档类型并仍然将其称为 HTML5 是完全可以接受的。
This is a comment, but I do not have enough karma points to put it in the correct place. Sigh.
No, your XSLT processor is not broken, it's just that XDV adds:
<xsl:output method="xml" indent="no" omit-xml-declaration="yes" media-type="text/html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
by default, so when you add a second
<xsl:output doctype-system="about:legacy-compat"/>
the previousdoctype-public
is not overwritten.Note that XHTML 1.0 strict is listed as an obsolete permitted doctype string, so it is perfectly acceptable to use this doctype and still call it HTML5.
抱歉,仅提供链接,但这已在 WHATWG 小组中讨论过,但我已经好几个月没有处理过它了。 Ian Hickson 和一些 XML 专家对此进行了讨论:
http://lists.w3.org/Archives/Public/ public-html/2009Jan/0640.html
http://markmail.org/message/64aykbbsfzlbidzl
这是实际的问题编号:
http://www.w3.org/html/wg/tracker/issues/ 54
这是这个讨论
http://www.contentwithstyle.co.uk/content/ xslt-and-html-5-问题
Sorry to only provide links but this was discussed among the WHATWG group but it's been many months since I've dealt with it. Here Ian Hickson and some XML experts discuss this:
http://lists.w3.org/Archives/Public/public-html/2009Jan/0640.html
http://markmail.org/message/64aykbbsfzlbidzl
and here is the actual issue number:
http://www.w3.org/html/wg/tracker/issues/54
and here's this discussion
http://www.contentwithstyle.co.uk/content/xslt-and-html-5-problems
使用此标签
Use this tag
如果保存为
html5.xml
,以下代码将作为独立模板使用:参考
The following code will work as a standalone template if saved as
html5.xml
:References
这就是我用来生成兼容的 html5 文档类型(获取 saxons html5,否则做遗留的事情)
that's what i use to generate a compatible html5 doctype (getting saxons html5 out, otherwise doing the legacy thing)