Subject: [xsl] Schema-aware validation of XHTML result-document|
From: "Jesper Tverskov" <jesper@xxxxxxxxxxx>
Date: Wed, 28 Feb 2007 15:29:51 +0100
It is nice that we with XSLT 2.0 schema-awareness can test if our output is valid, e.g. that it is valid XHTML, and that the transformation stops if it is not.
I have tested the concept with XMLSpy 2007 and SAXON 8SA as implemented in Oxygen and it raises several questions.
In XMPSpy there is a bug. The XML Schema schema of XHTML is not imported if http is used, but XMLSpy works if I download the schema to my harddisk and use a relative URL. Altova has accepted that there is a bug.
In SAXON as implemented in Oxygen it works but it took half a day to find out that default settings of SAXON in Oxygen is that the input document is also validated. That is the transformation only works if your input document is also XHTML or if you also import the schema of the input document or if you turn the validation of input documents off in some configuration menu of OXYGEN. Nice with all those options but I found it a bit confusing.
Here is my question. The spec tells us that the default-validation attribute of the stylesheet element can only have the values "strip" and "preserve". OXYGEN proposes those values but some tooltip is also telling us that we can use the values "strict" and "lax". That is what Michael Kay is also telling us in his book XSLT 2.0 based on early drafts.
The amazing thing is, that if I use "strict" as value in the default-validation attribute of the stylesheet element, SAXON works much better than if the result-document's validation attribute is "strict".
Now I don't even have to try to make a transformation in order to be warned of validation errors in my XHTML. I am told about validation errors right away, and the validation error message is also much better?
My test stylesheet does not make use of anything in the input document, any input document should work.
<?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:import-schema namespace="http://www.w3.org/1999/xhtml" schema-location="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"/> <xsl:template match="/"> <xsl:result-document exclude-result-prefixes="xs" href="myxhtml.html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" validation="strict"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Great XHTML test</title> </head> <body> <h1>Great XHTML test</h1> <p>Some text.</p> </body> </html> </xsl:result-document> </xsl:template> </xsl:stylesheet>
Cheers Jesper Tverskov