Validating xml with Schematron

Poster Content
nk4um User
Posts: 2
April 23, 2009 17:01
Hi,

I have found the solution for my problem. If I swith the context to element telecom then it works easily. However, Roger Costello (Who has provided nice schematron tutorials over internet) has given me another solution. to write rule on individual telecom element. Its given hereunder:

<sch:rule context="author/telecom[starts-with(@value, ''TEL'')]>...</sch:rule>

<sch:rule context="author/telecom[starts-with(@value, ''FAX'')]>...</sch:rule>

<sch:rule context="author/telecom[starts-with(@value, ''MAILTO'')]>...</sch:rule>

I am posting this because it might help some other fellow.

Regards,

Qarshi
nk4um User
Posts: 2
April 23, 2009 09:40Validating xml with Schematron
Hi,

I am using schematron to validate my xml file. I am stuck at some place during the validation. I have tried to find solution on internet but couldn''t.

I would request you to please give me a helping hand.

My source XML data and schematron for it looks like:

<author>
   <name>
     <given>Andrew</given>
     <family>Johns</family>
   </name>
  <telecom value="TEL:123456789"></telecom>
  <telecom value="FAX:123456799"></telecom>
  <telecom value="MAILTO:abc@xyz.com"></telecom>
</author>
------------------------------------------------------------------------------------------------------------------------
<sch:rule context="author">
    <sch:report test="telecom/@value and starts-with(fda:telecom/@value,''TEL'') and not (number(substring(fda:telecom/@value,5)) = number(substring(fda:telecom/@value,5)) and 50 > string-length(fda:telecom/@value))" >   
        Element telecom/@value must be a valid telephone number having max 46 numeric values.
    </sch:report>           
    <sch:report test="fda:telecom/@value and starts-with(fda:telecom[@value],''FAX'') and not (number(substring(fda:telecom/@value[2],5)) = number(substring(fda:telecom/@value[2],5)) and 100 > string-length(fda:telecom/@value))" >   
        Element telecom/@value must be a valid fax number having max 96 numeric values.
    </sch:report>   
    <sch:report test="fda:telecom/@value and starts-with(fda:telecom[@value],''MAILTO'') and string-length(fda:telecom/@value) > 100" >           
        Element telecom/@value must be 1-100 characters.
    </sch:report>   
</sch:rule>

Now the problem is that it only validates the attribute value of first instance of telecom. Rest of the elements are not validated.

Can you help me to find out how to resolve this issue.


Regards,
Qarshi