Jeroen,

Look through archives for discussion why Schematron was selected.
Schematron is XSLT based, writing and integrating processor is simple.
Also, validation may be done piecemeal (adding a few rules at a time as
needed).

Methinks schematron good for some kinds of *rule based* validation, but for
type based validation not so good.  If you want to use schematron you will
need to check out the XLST functions.  Also, remember you can create your
own  XLST (extension) functions.

I have appended some examples (using standard XSLT functions).

Cheers,
--Michael


<!-- validate set of checkboxes named "foo" -->
<rule context="/">
      <assert test="foo[1]='abc' or foo[1]='def' or foo[1]='ghi' or
foo[1]='jkl'">
            Please indicate whether you choose abc, def, ghi, or jkl
      </assert>
</rule>

<!-- same checkboxes, but can't select more than two at a time -->
<rule context="/">
      <assert test="foo[3]=''">
            You cannot choose more than two types of foo.
      </assert>
</rule>

<!-- validate three separate text boxes that comprise complete social
security number -->
<rule context="(/ss_num1 | /ss_num2) | /ss_num3">
      <assert test=".!=''">
            Please provide a complete social security number.
      </assert>
      <assert test="floor(.)=number(.) or .=''">
            Social security number must be an integer.
      </assert>
</rule>

<!-- Name  is required and cannot contain special characters -->
<rule context="/Name">
      <assert test=".!=''">
            Please provide a name.
      </assert>
      <report
test="contains(translate(.,'[EMAIL 
PROTECTED]&amp;*()_+-=0123456789','************************'),'*')">
            Name  contains an  illegal character.
      </report>
</rule>

<!-- Name is required and cannot contain *, #, ?, or &
<rule context="/name">
      <assert test=".!=''">
            Please provide a name.
      </assert>
      <assert test="not(contains(.,'*') or contains(.,'#') or
contains(.,'?') or contains(.,'&amp;'))">
            Name contains an illegal character.
      </assert>
</rule>

<!-- validating a select list -->
<rule context="/some_select_list">
      <assert test=". != 'IV'">You cannot select "IV" (for demo
purposes).</assert>
</rule>

<!-- one widget value not same as another widget value -->
<rule context="/">
      <assert test="/first_name!=/middle_name">
            First Name should not be the same as Middle Name.
      </assert>
</rule>

<!-- state is required and can't be Guam -->
<rule context="/state">
      <assert test=".!=''">Please select a State.</assert>
      <assert test=".!='GU'">Guam?  You expect me to believe you live in
Guam?</assert>
</rule>

<!-- zip code is required, must be an integer, and must contain between
five and nine digits
<rule context="/zip">
      <assert test=".!=''">Please provide a Zip/Postal Code.</assert>
      <assert test="floor(.)=number(.) or .=''">Zip/Postal Code must be an
integer.</assert>
      <assert test="(string-length(.) &gt; 4 and string-length(.) &lt; 10)
or .=''">
            Zip/Postal Code must contain at least five and at most nine
digits.
      </assert>
</rule>

<!-- email (if provided) must contain a dot and an at-sign
<rule context="/email">
      <assert test=".='' or (contains(.,'@') and contains(.,'.'))">
            Email Address has the wrong format.
      </assert>
</rule>

<!-- "foo", if provided must contain a seven-digit number -->
<rule context="/foo">
      <assert test=".!=''">Please provide a foo.</assert>
      <assert test="floor(.)=number(.) or .=''">foo must be a
number.</assert>
      <assert test="not(string-length(.)=4)">foo must contain seven
digits.</assert>
</rule>





                                                                                       
                  
                      Jeroen Cranendonk                                                
                  
                      <[EMAIL PROTECTED]        To:       [EMAIL PROTECTED]            
           
                      xx.nl>                   cc:                                     
                  
                                               Subject:  more xmlforms + schematron, 
why ?               
                      03/13/03 07:50 AM                                                
                  
                      Please respond to                                                
                  
                      cocoon-dev                                                       
                  
                                                                                       
                  
                                                                                       
                  




Looking at xmlforms and schematron more closely, I'm starting to
wonder why this combination was chosen anyways? from the examples
it seems the purpose of schematrons is to validate input fields, but
checking
something simple as if a field is only alpha characters seems to be near
impossible or atleast really hard with schematron (or am I missing
something
here ? )
Isn't schematron intended for checking document structure, not validity of
single fields/elements ?

Could someone eleborate on this ? please ? :)
and if anyone does have a simple idea of how to do a simple check with
schematron for alpha or non alpha strings ( 'test' is good, 'test1' or
'test#' is bad ) I'd be very gratefull for that too :)

Many thanks in advance,
             Jeroen Cranendonk



Reply via email to