OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML Schemas: Best Practices



Francis Norton wrote:
> The way I solved this was to write a very simple XSLT stylesheet that simply
> finds all the element from the Schematron namespace within the <xsd:appinfo>
> element in my XSD Schema. The stylesheet concatenated all this Schematron
> information to a Schematron schema which could be used for validating the
> things XSD could not validate (NOTE: this idea came from Rick Jelliffe [1]).
> By using the command line version of XSV, Saxon and a simple batch file I
> could do all the validation in one step.
>
You're ahead of me here - I haven't yet implemented this. Would you be
inclined to post a minimum-but-complete example? With my FAQ hat [1] on
this might be a good answer to both "what's xsd:appinfo for?" and "how
do I do co-constraint validation in the current version of XML Schema?"
[2].
Sure. I've just created a small demo that demonstrates this. At [1] you'll find a zip file which contains all the stylesheets and example files I used. I've modeled a ping-pong tournament with participants teams and matches for which I've created an XSD schema and instance. In the tournament you can choose to play single or double matches. XSD is not enough to do a complete validation so I use Schematron to validate for example that if you're playing double matches then the number of participants in the tournament must be divisible by two etc., etc. This Schematron validation info is included in the XSD Schema file in the <xsd:appinfo> element. By running the XSD2Schtrn.xsl style sheet the Schematron information is extracted form the XSD Schema and turned into a Schematron schema which can be used to validate the instance. I've created a batch file (validate.bat) which runs both XSV validation and Schematron validation on the instance.

When unziped it'll create a Demo directory in which you'll find the following files:

Tournament.xml
The XML instance file

Tournament.xml_sch
The Schematron schema file which is automatically created with XSD2Schtrn.xsl

Tournament.xsd
The XSD Schema for the tournament including the Schematron info. Make sure that you use the prefix sch: for the schematron information and that you add the schematron namespace in the XSD Schema (by adding xmlns:sch="http://www.ascc.net/xml/schematron" to the <xsd:schema> element)

validate.bat
The batch file that runs the complete validation. It takes two arguments where the first argument is the xml file (Tournament.xml) and the second argument is the XSD Schema file (Tournament.xsd). To be able to rune the validation you need to install the command-line version of XSV ([2]) and Saxon ([3]). In the batch file you need to change the location of these to applications to you're own configuration.

validate.xsl
The validation stylesheet that is automatically created by Schematron (schematron-basic.xsl).

The directory Stylesheet contains the following files:

skeleton1-5.xsl
The Schematron skeleton used as the basis for converting the Schematron schema to a validating stylesheet.

schematron-basic.xsl
The basic stylesheet that extends some of the functions in skeleton1-5.xsl to output the validation results in a simple and easy to read way.

XSD2Schtrn.xsl
The XSLT stylesheet I created to extract the Schematron information from the XSD Schema. Note that this is a very simple version that has several limitations:

1) The first <xsd:appinfo> element in the schema (I always put it as the first child of the <xsd:schema> element) must contain the <sch:title> element and the <sch:ns> elements if you want to use these.

2) Since the stylesheet just extracts the Schematron information in the order it appears in the document you need to group everything at the <sch:pattern> level. I.e. for each new <xsd:appinfo> element you creates you need to wrap the schematron information in <sch:pattern>.

3) I haven't tested the stylesheet with diagnostics and phases but it should work as long as you put the diagnostics and phases information in an <xsd:appinfo> at the end of the XSD Schema document.

4) It only supports one XSD Schema "level". I.e. if you import other schema files in your main schema only the Schematron information from the first schema will be extracted (I have a more advanced stylesheet that implements this partially)

I think that's all the information you'll need so please try it out and let me know what you think. Note that I've only tested using instant-saxon 6.2.1 [3].

Cheers,
/Eddie

[1] www.allette.com.au/Demo/XSD_Schtrn/Demo.zip
[2] ftp://ftp.cogsci.ed.ac.uk/pub/XSV/
[3] http://users.iclway.co.uk/mhkay/saxon/saxon6.2.1/instant-saxon.zip