[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Can XML Schema be compiled to Schematron?


xml schema to schematron
 From: "Doug Ransom" <Doug.Ransom@p...>
 
> I have been thinking that it would be an interesting exercise to implement a
> compiler that transforms XML Schema into Schematron (probably in XSLT).  
 
You might start by processing your instance document with Francis Norton's
TypeTagger  XSLT scripts, which add the type names (of elements) to
an instance. That will simplify life a lot, because then the Schematron
schema has access to type information from its XPath 1.0. 

For translating an XML Schema into Schematron, you need to implement
three parts:
  1) Keyref and uniqueness. I think this would be very simple to implement.

  2) Datatypes.  Because datatypes in XML Schemas only derive each
  other by restriction, you can merely add an extra set of assertion for every
  restriction. For example, if you have a string type X restricted to 15characters,
   you can make an assertion to test that. If there is also a derived type X' 
   restricted to 10 characters, you can add an extra assertion for that too.
  The difficulty here would be that converting perl regular expressions to 
   the simple string operations in XSLT expressions might be a little 
  challenging.

  3) Structures.  The lion's share of content models can be expressed
   in any of the schema languages; the edge cases are imporant,
   but may be difficult. 

    One interesting approach is to generate every possible path in the
    document. Instead of slicing the structure up vertically, you are slicing
   it horizontally.
   
   So  for HTML you might make rules for all these paths
     /html
    /html/head
    /html/head/title[count(../title)=1]
    /html/head/meta
    /html/body[count(../body)=1]
    /html/body/p
    table/tr
    table/tr/td
    table/tr/th
    ul/li
    ol/li
    dl/dt
    dl/dd[preceding-sibling::dt]
    ...
  and then a rule that reports any element that does not fit one of the rules,
  or other patterns such as that  a/../a is an error.

   The interesting part, good for a bit of thought or a research project, would be
    to figure out how to automatically derive the correct tests (in the brackets)
    which give various kinds of position information. Also, the optimal length
    of each path is interesting:  presumably there would be efficiency
    considerations for different policies. 

   It is perhaps a distinctive enough approach that it could have a schema
   language all of its own ("chain" would be a good name), but I don't have 
   the energy. 

Cheers
Rick Jelliffe


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.