cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: more xmlforms + schematron, why ?
Date Fri, 14 Mar 2003 00:59:51 GMT


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

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).


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

<!-- 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.

<!-- 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 test="floor(.)=number(.) or .=''">
            Social security number must be an integer.

<!-- Name  is required and cannot contain special characters -->
<rule context="/Name">
      <assert test=".!=''">
            Please provide a name.
            Name  contains an  illegal character.

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

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

<!-- 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.

<!-- 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

<!-- 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
      <assert test="(string-length(.) &gt; 4 and string-length(.) &lt; 10)
or .=''">
            Zip/Postal Code must contain at least five and at most nine

<!-- 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.

<!-- "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
      <assert test="not(string-length(.)=4)">foo must contain seven

                      Jeroen Cranendonk                                                  
                      <j.cranendonk@ema        To:    
            >                   cc:                                    
                                               Subject:  more xmlforms + schematron, why ?
                      03/13/03 07:50 AM                                                  
                      Please respond to                                                  

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
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
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

View raw message