RE: [xsl] Good or Bad should XSL validate tempaltes against a DTD/Schema

Subject: RE: [xsl] Good or Bad should XSL validate tempaltes against a DTD/Schema
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 24 Mar 2010 16:47:40 -0000
> I've been doing some work recently with a FOSI and I've 
> rediscovered that a FOSI is aware of the DTD that it is 
> applied to. What I mean is that if I test for an attribute 
> name or an enumerated value and that doesn't exist in the DTD 
> I get a warning from the FOSI compiler. With XSLT I have 
> several times hada typo in an element name or attribute and 
> never gotten a warning and have sometimes spent hours trying 
> to figure out why the stylesheet is not doing what I expected.
> 
> Seems to me like this would be a good thing, do you see any 
> downside to this?


A schema-aware XSLT 2.0 processor does this, and there are considerable
benefits in terms of faster debugging. However, the process is not fully
automatic, because it relies on you declaring your types. For example, if
you have a template rule with match="employee", that's not good enough to
ensure checking against the schema content model for employees, because
there might be several schema definitions for employee depending on the
context, or you might be processing data (for example update transactions)
that aren't valid against the schema. So you have to declare your intent by
saying match="schema-element(employee)". But it's worth the effort -
sometimes if I'm struggling with a stylesheet that doesn't work and I don't
understand how it was supposed to work, I'll go through it and make it
schema-aware as the quickest way of getting the bugs out.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread