Jens
Jens

Reputation: 9120

Check if XSLT stylesheet matches XML files of a given XSD schema

I am writing an XSLT stylesheet to transform XML files, and I'd like to make sure that I've covered all possibilities.

Is there a way to check that the XSLT stylesheet is valid and complete wrt a given XSD schema? Of course, the input XML is required to validate against that schema. (There is "schema-aware XML processing" but that's not quite what I'm looking for.)

Upvotes: 0

Views: 635

Answers (1)

kjhughes
kjhughes

Reputation: 111491

Wanting an XSLT stylesheet to be "valid and complete wrt a given XSD schema" sounds good but has a number of problems:

  1. There is no existing definition of such a validation. As you say, the input XML can certainly be validated against an XSD. The XSLT stylesheet itself can be validated on its own to check for compliance with the XSLT grammar. Together, however, no definition of validation exists.
  2. There is no clear notion of what such a definition should be. Even ignoring the "valid" part and focusing only on the "complete" part of your request, the method and benefit are still undefined. As @Flyn1179 suggested, you might try to define a default template that, when matched, signals a problem. You could draw the line that if any of the built-in templates gets invoked, your replacement error signal instead is triggered. Not all stylesheets have to handle all nodes, though, and many properly rely on the default templates.

Also, the errors that commonly occur in stylesheets go beyond mere matters of omission. Pattern matching and XPath construction mistakes are more common that neglecting to cover transformation of an element allowed by an XSD.

OTOH, a tool, or an XSLT/XPath processor feature, that would report when a given XPath could not possibly match anything in any XML document valid against a given XSD would save countless people countless hours of head scratching.

Upvotes: 1

Related Questions