home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 160 - Disc 2 / MF_UK_160_2.iso / pc / DiscContent / Trials / oxygen / samples / schematron / po / po-schema.sch < prev    next >
Encoding:
Text File  |  2005-07-21  |  4.2 KB  |  96 lines

  1. <!-- Schematron structural schema to validate purchase orders -->
  2. <!-- Note: content models are treated as "open". -->
  3. <!-- 2001-06-13 -->
  4. <!--
  5.  Copyright (c) 2001 Rick Jelliffe, Topologi Pty/ Ltd 
  6.  
  7.  This software is provided 'as-is', without any express or implied warranty. 
  8.  In no event will the authors be held liable for any damages arising from 
  9.  the use of this software.
  10.  
  11.  Permission is granted to anyone to use this software for any purpose, 
  12.  including commercial applications, and to alter it and redistribute it freely,
  13.  subject to the following restrictions:
  14.  
  15.  1. The origin of this software must not be misrepresented; you must not claim
  16.  that you wrote the original software. If you use this software in a product, 
  17.  an acknowledgment in the product documentation would be appreciated but is 
  18.  not required.
  19.  
  20.  2. Altered source versions must be plainly marked as such, and must not be 
  21.  misrepresented as being the original software.
  22.  
  23.  3. This notice may not be removed or altered from any source distribution.
  24. -->
  25.  
  26. <schema  xmlns="http://www.ascc.net/xml/schematron">    <title>Schema for Purchase Order Example</title>
  27.     <pattern name="Purchase Orders">
  28.         <rule context="*[shipTo or billTo or items]">
  29.         <!-- This rule couples the elements of the address type together, so that
  30.             if one appears anywhere, the others must also. -->
  31.             <assert test="shipTo"   icon="bug_10.gif"
  32.             >A purchase order should have a  shipTo element.</assert>
  33.             <assert test="billTo"   icon="bug_10.gif"
  34.             >A purchase order should have a billTo element.</assert>
  35.             <assert test="items"   icon="bug_10.gif"
  36.             >A purchase order should have an items element.</assert>
  37.                                            <assert test="@orderDate"   icon="bug_10.gif"
  38.             >A purchase order should have an orderDate attribute.</assert>
  39.             <assert test="*//shipDate"   icon="bug_10.gif"
  40.             >A purchase order should have an shipDate element.</assert>
  41.         </rule>
  42.         <rule context="/shipTo | /billTo | /items">
  43.             <report test="self::*"   icon="bug_11.gif"
  44.             >The element <name/> is not expected
  45.             at the top of a document. It should be in
  46.             the body of a purchase order.</report>
  47.         </rule>
  48.     </pattern>
  49.     <pattern name="US Address" >
  50.  
  51.     <!-- This pattern simulates complex types: we don't care about the
  52.                      element name, but we desire certain children -->
  53.         <rule context="*[name or street or  city or state or zip]">
  54.         <!-- This rule couples the elements of the address type together, so that
  55.         if one appears anywhere, the others must also. -->
  56.             <assert test="name"  icon="bug_10.gif"
  57.             >An address should have a name.</assert>
  58.             <assert test="street"  icon="bug_10.gif"
  59.             >An address should have a street.</assert>
  60.             <assert test="city"  icon="bug_10.gif"
  61.             >An address should have a city.</assert>
  62.             <assert test="state"  icon="bug_10.gif"
  63.             >An address should have a state.</assert>
  64.             <assert test="zip"  icon="bug_10.gif"
  65.             >An address should have a zip.</assert>
  66.         </rule>
  67.         <rule context="/street | /name | /city | /state | /zip">
  68.         <report test="self::*"   icon="bug_11.gif"
  69.         >The elements <name/> is not expected at
  70.         the top of a document. They form part of an address.</report>
  71.         </rule>
  72.         </pattern>
  73.         
  74.         <!-- Next, the specific elements -->
  75.         <pattern name="Specific Elements">
  76.                 <rule context="items">
  77.                 <assert test="count(child::*) = count(child::item)"   icon="bug_11.gif"
  78.                 >The items element can only contain item elements</assert>
  79.                 </rule>
  80.                 <rule context="item">
  81.                 <assert test="productName"   icon="bug_10.gif"
  82.                 >The item element should contain a product name. </assert>
  83.                 <assert test="quantity"   icon="bug_10.gif"
  84.                 >The item element should contain a quantity element </assert>
  85.                 <assert test="USPrice"   icon="bug_10.gif"
  86.                 >The item element should contain a USPrice element.  </assert>
  87.                 </rule> 
  88.                 <rule context="comment"  >
  89.                 <report test="child::*"   icon="bug_7.gif"
  90.                 >A comment should have no subelements</report >
  91.                 <assert test="parent::item | parent::purchaseOrder "   
  92.             icon="bug_7.gif"
  93.             >A comment can only appear in an item or a purchase Order</assert>
  94.             </rule>
  95.         </pattern>
  96. </schema>