RE: is this a job for schematron?

"Peter Aberline" <[email protected]> Wed, 7 Apr 2004 09:50:21 +0100
Newsgroups gmane.text.xml.schematron
Message-ID <OFD3CC4AE3.D18F132B-ON80256E6F.002F7026-80256E6F.00308DB8@wcg.co.uk>
Hi Eddie,

Many thanks for the suggestion, and also thanks to the other list members
who replied too. I think I will proceed with your suggested solution of
embedding Schematron rules in W3C schemas.

I prefer this approach to RELAX NG for reasons of supportability and
maintainability - Schematron appears to complement W3C standards using
standard technology, and so is a better fit to our application design.

cheers,
Peter.



Registered Number 181116 England and Wales


                                                                                                                                                
                      "Edvard Robertsson"                                                                                                       
                      <[email protected]>                      To:       [email protected]                                                  
                      Sent by:                                   cc:       [email protected]                             
                      [email protected]        bcc:      Peter Aberline/Lon/GB/WCG                                            
                      ceforge.net                                Subject:  RE: [Schematron-love-in] is this a job for schematron?               
                                                                                                                                                
                                                                                                                                                
                      06/04/2004 20:28 GDT                                                                                                      
                                                                                                                                                
                                                                                                                                                




Hi Peter,

>Instead, would it be better to define a schema that allows any elements
>under letters, and then use schematron to test if particular elements are
>there, and of the correct datatype? Can schematron do this? Any advice
>would be greatly appreciated.

One solution to your problem is to use embedded Schematron rules in WXS
unless you want to switch to RELAX NG which probably can do the things you
ask. I wrote an article on embedding Schematron rules in other XML Schema
languages [1] some time ago which should give you the basics on how to
proceed. The basic idea is to use WXS to validate the basic constraint and
then embedd Schematron rules within the xs:appinfo element to enforce the
added constraints. In your case the Schematron rule can look like the one
Oliver suggested in another post to this list:

<rule context="letters">
   <assert test="count(a)=1">letters must contain one a element</assert>
   <assert test="count(b)=1">letters must contain one b element</assert>
   <assert test="count(c)=1">letters must contain one c element</assert>
</rule>

The complete WXS schema with the embedded constraints can look like this:

<?xml version="1.0" encoding="UTF-8"?><?xar W3C XML Schema?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns:sch="http://www.ascc.net/xml/schematron">
    <xs:element name="letters">
       <xs:annotation>
          <xs:appinfo>
             <sch:pattern name="Check for a, b and c">
                <sch:rule context="letters">
                   <sch:assert test="count(a)=1">letters must contain one a

element</sch:assert>
                   <sch:assert test="count(b)=1">letters must contain one b

element</sch:assert>
                   <sch:assert test="count(c)=1">letters must contain one c

element</sch:assert>
                </sch:rule>
             </sch:pattern>
          </xs:appinfo>
       </xs:annotation>
       <xs:complexType>
          <xs:sequence>
             <xs:any namespace="##any" processContents="skip" minOccurs="0"

maxOccurs="unbounded"/>
          </xs:sequence>
       </xs:complexType>
    </xs:element>
    <xs:element name="root">
       <xs:complexType>
          <xs:sequence>
             <xs:element ref="letters" maxOccurs="unbounded"/>
          </xs:sequence>
       </xs:complexType>
    </xs:element>
</xs:schema>

For more information on validation and processing see the article on the
Topologi website [1]

Cheers,
/Eddie

[1] http://www.topologi.com/resources/schtrn_xsd_paper.html

>
>many thanks,
>Peter
>
>_____________________________________________________________
>
>The information in this email and in any attachments is confidential and
>may be privileged.  If you are not the intended recipient, please destroy
>this message, delete any copies held on your systems and notify the sender
>immediately.  You should not retain, copy or use this email for any
>purpose, nor disclose all or any part of its content to any other person.
>
>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: IBM Linux Tutorials
>Free Linux tutorial presented by Daniel Robbins, President and CEO of
>GenToo technologies. Learn everything from fundamentals to system
>administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
>_______________________________________________
>Schematron-love-in mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/schematron-love-in

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Schematron-love-in mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/schematron-love-in




_____________________________________________________________

The information in this email and in any attachments is confidential and
may be privileged.  If you are not the intended recipient, please destroy
this message, delete any copies held on your systems and notify the sender
immediately.  You should not retain, copy or use this email for any
purpose, nor disclose all or any part of its content to any other person.





-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click