Search code examples
xmlxpathxqueryschematron

Schematron validating multiple elements


Assume I have an XML document defining:

<people>

  <person>
    <city>London</city>
  </person>
  <person>
    <city>Paris</city>
  </person>

</people>

I want a schematron that check that each person lives in London.

I tried:

<sch:rule context="people">
            <sch:assert test="person/city = 'London'">Everybody must live in London!</sch:assert>
 </sch:rule>

However, this will return true so long as there exists one person that lives in London. Is there a way I can tell schematron to apply a test to each element matching the XPathcondition person/city ?


Solution

  • How about "no one may live outside London":

    <sch:rule context="people">
        <sch:assert test="not(person[city != 'London'])">Everybody must live in London!</sch:assert>
    </sch:rule>