Official XSLT validator?

前端 未结 3 1528
你的背包
你的背包 2021-02-19 04:21

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 docume

相关标签:
3条回答
  • In the general case you can't take an arbitrary XSLT stylesheet and prove statically that it will generate valid XHTML. You can however detect quite a few cases where it won't, provided that the stylesheet is written to take advantage of schema-awareness. For this you need a schema-aware XSLT processor that does static checking (for example Saxon-EE), and you need the stylesheet to (a) import the schema using xslt:import-schema, and (b) to invoke validation on the result elements using [xsl:]validation="strict". This will detect some validity errors in your stylesheet output statically (while compiling the stylesheet), and the remainder dynamically (while running it).

    0 讨论(0)
  • 2021-02-19 05:23

    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.

    0 讨论(0)
  • 2021-02-19 05:23

    There are many XML editing tools (and probably a few HTML ones as well) that know the structure of (X)HTML enough to highlight errors. Visual Studio for example can validate ANY XML document using the schema, including XHTML or XSL- Whether or not a div is allowed inside a span is defined in the XHTML schema.

    0 讨论(0)
提交回复
热议问题