xsl-list
[Top] [All Lists]

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

2004-10-24 03:03:02
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.

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.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/