Validating Cardinality

Roger Costello

Click arrow key () to navigate to next page

Example: Checking Reserved Words

  1. <?xml version="1.0"?>
  2. <Document classification="secret">
  3. <Para classification="unclassified">
  4. One if by land, two if by sea;
  5. </Para>
  6. </Document>

Different Type of Checking

Rule

  1. <sch:rule context="Document">
  2. <sch:assert test="count(//node()[contains(.,'SCRIPT')]) = 0
  3. and
  4. count(//node()[contains(.,'FUNCTION')]) = 0">
  5. The document must not contain the words SCRIPT or FUNCTION
  6. </sch:assert>
  7. </sch:rule>

Pattern

  1. <sch:pattern name="Reserved Word Filter">
  2. <sch:p>These reserved words are not allowed anywhere in the
  3. document: SCRIPT, FUNCTION.</sch:p>
  4. <sch:rule context="Document">...</sch:rule>
  5. </sch:pattern>

Schematron Schema

  1. <?xml version="1.0"?>
  2. <sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
  3. <sch:pattern name="Reserved Word Filter">
  4. <sch:p>These reserved words are not allowed anywhere in the
  5. document: SCRIPT, FUNCTION.</sch:p>
  6. <sch:rule context="Document">
  7. <sch:assert test="count(//node()[contains(.,'SCRIPT')]) = 0
  8. and
  9. count(//node()[contains(.,'FUNCTION')]) = 0">
  10. The document must not contain the words SCRIPT or FUNCTION
  11. </sch:assert>
  12. </sch:rule>
  13. </sch:pattern>
  14. </sch:schema>

Validate

Display All Errors?

Multiple Assertions

  1. <sch:rule context="Document">
  2. <sch:assert test="count(//node()[contains(.,'SCRIPT')]) = 0">
  3. The document must not contain the word SCRIPT
  4. </sch:assert>
  5. <sch:assert test="count(//node()[contains(.,'FUNCTION')]) = 0">
  6. The document must not contain the word FUNCTION
  7. </sch:assert>
  8. </sch:rule>

Validate

Reserved Words in External List

Reserved Words in External List

  1. <sch:pattern name="Reserved Word Filter (words from external document)">
  2. <sch:rule context="Para">
  3. <sch:assert test="count(.//node()[contains(., document('reserved-words-list.xml')/Reserved-Words/li[1])]) = 0">
  4. The Para element must not contain this reserved word
  5. </sch:assert>
  6. <sch:assert test="count(.//node()[contains(., document('reserved-words-list.xml')/Reserved-Words/li[2])]) = 0">
  7. The Para element must not contain this reserved word
  8. </sch:assert>
  9. <sch:assert test="count(.//node()[contains(., document('reserved-words-list.xml')/Reserved-Words/li[3])]) = 0">
  10. The Para element must not contain this reserved word
  11. </sch:assert>
  12. </sch:rule>
  13. </sch:pattern

Lab 2

Lab 2 (cont.)

Homepage