>> English << | českyZVON > Tutorials > Schematron Tutorial
>> Example 8 << | Prev | Next | Contents

Description

Test, if the source has the same number of both elements

Schema


<schema xmlns="http://www.ascc.net/xml/schematron" >
     <pattern name="Test count">
          <rule context="/*">
               <report test="count(//BBB) = count(//AAA)">O.K.</report>
               <assert test="count(//BBB) &lt;= count(//AAA)">Some AAA are missing</assert>
               <report test="count(//BBB) &lt; count(//AAA)">Some BBB are missing</report>
          </rule>
     </pattern>
</schema>

Sources and outputs

Source (XML 1)Output

<XXX>
     <BBB/>
     <BBB/>
     <AAA/>
     <BBB/>
     <AAA/>
     <AAA/>
</XXX>
 Pattern: Test count
/XXX: O.K.


Source (XML 2)Output

<XXX>
     <BBB/>
     <AAA/>
     <BBB/>
     <AAA/>
     <AAA/>
</XXX>
 Pattern: Test count
/XXX: Some BBB are missing


Source (XML 3)Output

<XXX>
     <BBB/>
     <BBB/>
     <AAA/>
     <BBB/>
     <AAA/>
</XXX>
 Pattern: Test count
/XXX: Some AAA are missing