RE: [xsl] Schema-aware validation of XHTML result-document

Subject: RE: [xsl] Schema-aware validation of XHTML result-document
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 28 Feb 2007 15:36:18 -0000
> 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.

Yes, I find this very useful. (There's also an option in Saxon to continue
after a validation failure, treating the errors as warnings. I found this
useful because sometimes you want to get the outline structure of the result
document right first, before you worry about the detail of every attribute,
and you want to see what the result looks like even if it's invalid.)

> Nice with all those options but I found it a bit confusing.

Yes, there's a lot of power there but also some complexity!
> 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.

We took out the values strict and lax, if I remember right, because they try
to validate every element, and this is usually overkill. For example, it
doesn't work if you have a temporary tree in your stylesheet that isn't
described by a schema, or if your schema makes extensive use of local
element declarations. 
> 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".

I'm sorry to disappoint you, but it's a bug in Saxon that it still allows
the values strict and lax here!

It was probably a mistake to take it out of the spec. As you say, it's quite
useful in the case of a schema like the XHTML schema where all the element
declarations are global - and that's an important use case.
To achieve the same effect without it (that is, compile-time static checking
of your templates against the schema), you have to put
xsl:validation="strict" on the outermost result element in each template
rule. To get run-time checking, though, it's enough to specify
validation="strict" on the xsl:result-document element.
> 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?

Yes, the thing I really like is to be told where the stylesheet is wrong,
rather than being given a list of 500 identical errors in the result
document, which I then have to trace back to the code in the stylesheet that
created them. (Although to be fair, there are some debugging tools e.g. in
Stylus STudio that can help you with this backmapping).

The other thing I like is that I can't accidentally forget to validate the

Michael Kay

Current Thread