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

Description

If the element has one attribute then it must have the second one as well.

Schema


<schema xmlns="http://www.ascc.net/xml/schematron" >
     <pattern name="Attributes present">
          <rule context="BBB">
               <assert test="not(@aaa) or (@aaa and @bbb)">The element must not have an isolated aaa attribute</assert>
               <assert test="not(@bbb) or (@aaa and @bbb)">The element must not have an isolated bbb attribute</assert>
          </rule>
     </pattern>
</schema>

Sources and outputs

Source (XML 1)Output

<AAA>
     <BBB aaa="A" bbb="B"/>
</AAA>
 Pattern: Attributes present


Source (XML 2)Output

<AAA>
     <BBB bbb="B"/>
</AAA>
 Pattern: Attributes present
/AAA/BBB: The element must not have an isolated bbb attribute


Source (XML 3)Output

<AAA>
     <BBB aaa="A"/>
</AAA>
 Pattern: Attributes present
/AAA/BBB: The element must not have an isolated aaa attribute


Source (XML 4)Output

<AAA>
     <BBB/>
</AAA>
 Pattern: Attributes present