官方 XSLT 验证器? [英] Official XSLT validator?

查看:23
本文介绍了官方 XSLT 验证器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何官方 XSLT 验证器,例如 http://validator.w3.org/ 用于 HTML &XHTML?

我知道 http://validator.w3.org/ 也可用于验证 XML 和 XSL 文档.但它们被验证为 XML 结构.

在有效的 XHTML 中,例如,

...

是无效的,因为块元素不应出现在线元素.

那么,有没有方便的方法,直接验证XSL文档?

(我猜我们可以结合 XML 和 XSL,输出 XHTML,然后验证它.但这不是直接的,也不方便.)

谢谢!

解决方案

我假设通过验证 XSLT 样式表,您的意思是检查已经格式良好的 XML 文档(似乎是 XSLT 代码)中的元素、属性等是否符合到 XSLT W3C 规范.

首先,请注意 XML 文档的格式良好和有效性之间存在差异.如果包含的元素正确嵌套,如果有单个根元素等等(这是由 XML 规范定义的),则它是格式良好的.另请参阅:'validxml'和'格式良好的 xml'? .

XML 文档的有效性只能与 XML 模式(或 DTD,或 RelaxNG...)一起验证.模式是一组规则,例如定义允许以什么顺序使用哪些元素和属性.

现在,回答你的问题:W3C 没有这样的服务,但是,有一个可用的模式,参见例如http://www.w3.org/2007/schema-for-xslt20.xsd 用于包含标准"XSLT 2.0 的所有结构的模式.

您可以根据此架构验证您的 XSLT 代码.不过,使用 XSLT 处理器运行您的代码并查找它产生的警告和错误会更有见地.

<小时>

此外,请注意 XSLT 代码的有效性和它输出的 XHTML 的有效性是不一样的.即使您的 XSLT 相对于 XSLT 规范完全有效,也不意味着生成的 XHTML 是合理的.

Is there any official XSLT validator, like http://validator.w3.org/ for HTML & XHTML?

I know http://validator.w3.org/ can also be used to validate XML and XSL documents. But they are validated as XML structures.

In valid XHTML, for example, <span><div>...</div></span> is invalid, as block elements should not appear inside in-line elements.

So, is there a convenient way, to directly validate the XSL document?

(i guess we may combine XML and XSL, output the XHTML, then validate it. But this is not directly and not convenient.)

Thanks!

解决方案

I assume that by validating XSLT stylesheets you mean checking whether the elements, attributes etcetera in an already well-formed XML document (which appears to be XSLT code) adhere to the XSLT W3C specification.

First of all, note that there is a difference between the well-formedness and validity of an XML document. It is well-formed if the contained elements are properly nested, if there is a single root element and so forth (this is defined by the XML specification). Also see: Is there a difference between 'valid xml' and 'well formed xml'? .

The validity of an XML document can only be verified together with an XML schema (or DTD, or RelaxNG...). A schema is a set of rules defining, for example, which elements and attributes are allowed in what sequence.

Now, to answer your question: There is no such service from W3C, however, there is a schema available, see e.g. http://www.w3.org/2007/schema-for-xslt20.xsd for a schema that incorporates all the structures of "standard" XSLT 2.0.

You can validate your XSLT code against this schema. Still, it is more insightful to just run your code with an XSLT processor and look for the warnings and errors it produces.


Besides, be aware that the validity of XSLT code and the validity of the XHTML it outputs is not the same. Even if your XSLT is perfectly valid with respect to the XSLT specification, it does not mean that the resulting XHTML is reasonable.

这篇关于官方 XSLT 验证器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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