xsl-list
[Top] [All Lists]

Re: XSLT 2.0 *and* XSLT 1.0 validation -- how to?

2004-10-24 04:39:56
Hi Jeni,


On Sun, 24 Oct 2004 11:03:02 +0100, Jeni Tennison 
<jeni(_at_)jenitennison(_dot_)com> wrote:
Hi Dimitre,



My question was, could there be a single schema that has both the
rules for XSLT 1.0 and the rules for XSLT 2.0 and that, dependent on
the value of the "version" attribute of an instance behaves exactly
as an XSLT 1.0 schema only or exactly as an XSLT 2.0 schema only.

I can imagine doing this with a pre-processor, which only reads and
analyzes the xsl:stylesheet instruction, then depending on the
version attribute it validates with only one of two schemas. Or, if
rules in the schema can be based on a condition, it will set the
condition to true or false and then validate with a single combined
schema passing to it (e.g. setting this in DOM) the value of this
condition.

Can this be done?

The trouble is that XSLT allows regions of a stylesheet to belong to
different versions. In XSLT 1.0, you can put an xsl:version attribute
on any literal result element to indicate the version of XSLT used in
the content of that element. In XSLT 2.0, any XSLT element can have a
version attribute, and any other element can have a xsl:version
attribute that does the same thing.

Oh, I didn't know that... My first reaction is to wonder if such a
feature can be really useful.


So it's not as simple as looking at the version attribute on the
<xsl:stylesheet> element and choosing which version of the schema to
use based on that.

I think you could probably write a RELAX NG schema that used the
version switch correctly, wherever it was used (since RELAX NG
supports co-occurrence constraints, unlike XML Schema); I haven't
looked at Norm's, so I don't know whether his does that.

Personally, I don't think that it's worth validating XSLT stylesheets
against a schema. It's simpler, quicker, more accurate and more
helpful to get an XSLT processor to check your stylesheet instead.

I also thought so in the past, but one can quickly get a powerful
language construction/editing environment --  by simply providing a
schema to an intelligent editor one can get correct
structure/intellisense support. And this is an example of really good
use of schemas.

Cheers,

Dimitre.