[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XML Schemas: Best Practices
Francis Norton wrote: > The way I solved this was to write a very simple XSLT stylesheet that simplySure. 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
Tournament.xml_sch
Tournament.xsd
validate.bat
validate.xsl
The directory Stylesheet contains the following files: skeleton1-5.xsl
schematron-basic.xsl
XSD2Schtrn.xsl
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,
[1] www.allette.com.au/Demo/XSD_Schtrn/Demo.zip
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|