Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Official XSLT validator?

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!

like image 833
midnite Avatar asked Dec 16 '13 07:12

midnite


People also ask

How do I validate an XSLT file?

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".

Does anyone use XSLT anymore?

XSLT is very widely used. As far as we can judge from metrics like the number of StackOverflow questions, it is in the top 30 programming languages, which probably makes it the top data-model-specific programming language after SQL. But XSLT isn't widely used client-side, that is, in the browser.

How do I run XSL on Chrome?

Try running Chrome with the --allow-file-access-from-files flag. I've not tested this myself, but if it works, your system will now also be vulnerable to scenarios of the kind mentioned above. Upload it to a host, and problem solved.


2 Answers

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.

like image 182
Mathias Müller Avatar answered Oct 26 '22 10:10

Mathias Müller


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).

like image 28
Michael Kay Avatar answered Oct 26 '22 09:10

Michael Kay