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

Description

The element must have the attribute, if it is inside another one, but it must not have the one otherwise

Schema


<schema xmlns="http://www.ascc.net/xml/schematron" >
     <pattern name="Test attribute">
          <rule context="CCC">
               <report test="parent::BBB and not(@id)">Attribute id is missing</report>
               <report test="not(parent::BBB) and @id">Attribute id is used in wrong context</report>
          </rule>
     </pattern>
</schema>

Sources and outputs

Source (XML 1)Output

<AAA>
     <CCC/>
     <CCC/>
     <BBB>
          <CCC id="Q1"/>
     </BBB>
</AAA>
 Pattern: Test attribute


Source (XML 2)Output

<AAA>
     <CCC id="Q2"/>
     <CCC/>
     <BBB>
          <CCC id="Q1"/>
     </BBB>
</AAA>
 Pattern: Test attribute
/AAA/CCC[1]: Attribute id is used in wrong context


Source (XML 3)Output

<AAA>
     <CCC/>
     <CCC/>
     <BBB>
          <CCC/>
     </BBB>
</AAA>
 Pattern: Test attribute
/AAA/BBB/CCC: Attribute id is missing