OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] Using Schematron to define templates


On Wed, May 21, 2008 at 8:14 AM, Dick Hamilton <rlhamilton@frii.com> 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="imageobject[@role]">imageobject elements must have
@role</assert>
      <report test='imageobject[@role="print"]/imagedata[not(@format="PDF")]'>imageobject[@role="print"]/imagedata
must be @format="PDF"</report>
      <report test='imageobject[@role="web"]/imagedata[@format[not(.="PNG")
and not(.="JPG") and
not(.="GIF")]]'>imageobject[@role="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="imageobject[@role='print']">
      <assert test='imagedata[@format]'>imageobject elements must have
@format</assert>
      <assert test='imagedata[@fileref[starts-with(.,
"figs")]]'>imageobject[@role='print']/imagedata  must have a @fileref
starting with figs</assert>
    </rule>
    <rule context="imageobject[@role='web']">
      <assert test='imagedata[@format]'>imageobject elements must have
@format</assert>
      <assert test='imagedata[@fileref[starts-with(.,
"figs")]]'>imageobject[@role='web']/imagedata  must have a @fileref
starting with figs</assert>
    </rule>
  </pattern>
</schema>


HTH,
Keith


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]