RE: is this a job for schematron?

"Edvard Robertsson" <[email protected]> Tue, 06 Apr 2004 21:28:22 +0200
Newsgroups gmane.text.xml.schematron
Message-ID <[email protected]>
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