On Wed, May 21, 2008 at 8:14 AM, Dick Hamilton <[EMAIL PROTECTED]> wrote:
> Michael,
>
> Thanks for the pointers.  I like to work from examples, so they
> should be useful.

We're planning on spinning up Schematron (with XPath 2.0) for exactly
the same sort of stuff. Here's a very minimal example:

<?xml version="1.0"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron";>
  <title>O'Reilly Bookinfo Test</title>
  <pattern>
    <title>Check Book Elements for Bookinfo</title>
    <rule context="book">
      <assert test="bookinfo">Book elements must have an bookinfo child</assert>
      <assert test="title">Book elements must have an title child</assert>
    </rule>
  </pattern>
  <pattern>
    <title>Check Bookinfo for proper structure</title>
    <rule context="bookinfo">
      <assert test="count(isbn) = 1">bookinfo must have one and only
one isbn child</assert>
      <assert test="string-length(isbn[1]) = 13">isbn elements must be
13 characters long (no dashes or spaces)!</assert>
      <assert test="not(matches(isbn[1], '[^X0-9]'))">isbn elements
must only contain ==[X0-9]== characters!</assert>
      <assert test="count(publisher) = 1">Each book requires one
publishername</assert>
      <assert test="count(publisher/publishername) = 1">Each book
requires one publishername</assert>
      <report test="title">Book's title's should be in the book
element rather than the bookinfo</report>
    </rule>
  </pattern>
</schema>

<schema xmlns="http://purl.oclc.org/dsdl/schematron";>
  <title>O'Reilly Mediaobject Test</title>
  <pattern>
    <title>Check For No Graphics</title>
    <rule context="/">
      <report test="descendant::graphic">graphic elements not allowed</report>
      <report test="descendant::inlinegraphic">inlinegraphic elements
not allowed</report>
    </rule>
  </pattern>
  <pattern>
    <title>Check Mediaobject for proper structure</title>
    <rule context='mediaobject[not(@role="cover")]'>
      <assert test="[EMAIL PROTECTED]">imageobject elements must have
@role</assert>
      <report test='[EMAIL 
PROTECTED]"print"]/imagedata[not(@format="PDF")]'>[EMAIL 
PROTECTED]"print"]/imagedata
must be @format="PDF"</report>
      <report test='[EMAIL PROTECTED]"web"]/[EMAIL PROTECTED](.="PNG")
and not(.="JPG") and
not(.="GIF")]]'>[EMAIL PROTECTED]"web"]/imagedata must be
@format="PNG|GIF|JPG"</report>
      <report test='imageobject[not(@role = "web" or @role =
"print")]'>Use only @role="web" or @role="print" on imageobject
elements</report>
    </rule>
    <rule context="[EMAIL PROTECTED]'print']">
      <assert test='[EMAIL PROTECTED]'>imageobject elements must have
@format</assert>
      <assert test='[EMAIL PROTECTED](.,
"figs")]]'>[EMAIL PROTECTED]'print']/imagedata  must have a @fileref
starting with figs</assert>
    </rule>
    <rule context="[EMAIL PROTECTED]'web']">
      <assert test='[EMAIL PROTECTED]'>imageobject elements must have
@format</assert>
      <assert test='[EMAIL PROTECTED](.,
"figs")]]'>[EMAIL PROTECTED]'web']/imagedata  must have a @fileref
starting with figs</assert>
    </rule>
  </pattern>
</schema>


HTH,
Keith

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to