<xsl:output> 中的 xml、html 或 xhtml:哪个更好? [英] xml, html or xhtml in &lt;xsl:output&gt;: Which is the better choice?

查看:30
本文介绍了<xsl:output> 中的 xml、html 或 xhtml:哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于历史原因,我们混合了

在 XSL 文件的包含层次结构中.现在我们要重构以便所有 XSL 文件都使用相同的输出方法.

最后我们想要生成 XHTML 输出,所以我想后者是最好的选择.

但是这三种输出方法之间有什么区别,您将使用哪种解决方案?

我使用的是 XSLT 2.0

解决方案

我通过阅读 XSLT 2.0 规范 (XSLT 2.0 和 XQuery 1.0 序列化).

<块引用>

给定一个 XHTML 的空实例其内容模型不是的元素EMPTY(例如,空标题或段)序列化程序不得使用最小化形式.也就是说,它必须输出

而不是

.

给定一个 XHTML 元素,其内容模型是空的,序列化程序必须使用最小化的标签语法,对于示例 <br/>,作为替代XML 允许的语法

在许多情况下给出不确定的结果现有的用户代理.序列化器必须在前面包含一个空格尾随/>,例如
,


<img src="karen.jpg" alt="Karen"/>.

序列化程序不得使用实体参考 &apos; 虽然在 XML 中合法,因此在 XHTML 中,没有在 HTML 中定义,也不是被所有 HTML 用户代理识别.

序列化器应该输出命名空间声明方式是符合要求如果可能,XHTML DTD.这XHTML 1.0 DTD 需要声明xmlns="http://www.w3.org/1999/xhtml"出现在 html 元素上,以及仅在 html 元素上.这序列化程序必须输出命名空间符合的声明中存在的命名空间节点结果树,但它必须避免输出冗余命名空间DTD 元素的声明会使它们无效.

这意味着答案是使用 .

For historic reasons we have a mixture of

<xsl:output method="xml">

and

<xsl:output method="html">

and

<xsl:output method="xhtml">

inside an include-hierarchy of XSL files. Now we want to refactor so all XSL files use the same output method.

In the end we want to produce XHTML-output so I suppose the latter would be the best choice.

But what are the differences between those three output-methods and which would you use for what kind of solution?

Edit: I'm using XSLT 2.0

解决方案

I found the answer by reading the XSLT 2.0 specification (XSLT 2.0 and XQuery 1.0 Serialization).

Given an empty instance of an XHTML element whose content model is not EMPTY (for example, an empty title or paragraph) the serializer MUST NOT use the minimized form. That is, it MUST output <p></p> and not <p />.

Given an XHTML element whose content model is EMPTY, the serializer MUST use the minimized tag syntax, for example <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents. The serializer MUST include a space before the trailing />, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />.

The serializer MUST NOT use the entity reference &apos; which, although legal in XML and therefore in XHTML, is not defined in HTML and is not recognized by all HTML user agents.

The serializer SHOULD output namespace declarations in a way that is consistent with the requirements of the XHTML DTD if this is possible. The XHTML 1.0 DTDs require the declaration xmlns="http://www.w3.org/1999/xhtml" to appear on the html element, and only on the html element. The serializer MUST output namespace declarations that are consistent with the namespace nodes present in the result tree, but it MUST avoid outputting redundant namespace declarations on elements where the DTD would make them invalid.

That means the answer is using <xsl:output method="xhtml">.

这篇关于<xsl:output> 中的 xml、html 或 xhtml:哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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