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

Description

Test, if an element is empty

Schema


<schema xmlns="http://www.ascc.net/xml/schematron" >
     <pattern name="Select empty elements CCC">
          <rule context="CCC">
               <assert test="normalize-space(.) and *">Source contains an empty element CCC </assert>
               <report test="normalize-space(.) = ''">[1]An element CCC does not contain any text</report>
               <assert test="normalize-space(.)">[2]An element CCC does not contain any text</assert>
               <report test="not(*)">[1]An element CCC does not contain any child element</report>
               <assert test="*">[2]An element CCC does not contain any child element</assert>
          </rule>
     </pattern>
</schema>

Sources and outputs

Source (XML 1)Output

<AAA>
     <BBB>
          <CCC/>
     </BBB>
</AAA>
 Pattern: Select empty elements CCC
/AAA/BBB/CCC: Source contains an empty element CCC
/AAA/BBB/CCC: [1]An element CCC does not contain any text
/AAA/BBB/CCC: [2]An element CCC does not contain any text
/AAA/BBB/CCC: [1]An element CCC does not contain any child element
/AAA/BBB/CCC: [2]An element CCC does not contain any child element


Source (XML 2)Output

<AAA>
     <BBB>
          <CCC>I am CCC element</CCC>
     </BBB>
</AAA>
 Pattern: Select empty elements CCC
/AAA/BBB/CCC: Source contains an empty element CCC
/AAA/BBB/CCC: [1]An element CCC does not contain any child element
/AAA/BBB/CCC: [2]An element CCC does not contain any child element


Source (XML 3)Output

<AAA>
     <BBB>
          <CCC>
               <DDD/>
          </CCC>
     </BBB>
</AAA>
 Pattern: Select empty elements CCC
/AAA/BBB/CCC: Source contains an empty element CCC
/AAA/BBB/CCC: [1]An element CCC does not contain any text
/AAA/BBB/CCC: [2]An element CCC does not contain any text