cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John R. Callahan" <>
Subject Schematron transform in a Cocoon pipeline
Date Tue, 21 Jan 2003 20:58:09 GMT
This seems too simple, but I wanted to see if I could
use Schematron generated XSLT to validate some
XML in a Cocoon pipeline.  This might be used for
validating uploaded  XML files for example.

I downloaded the latest Schematron skeleton (1.5),
then generated some XSLT from a set of assertions,
and then put it into a transform in a pipeline with some

<map:match pattern="*.xml">
  <map:generate src="{1}.xml"/>
  <map:transform src="asserts1.xsl"/>
  <map:serialize type="xml"/>

<!-- build the Schematron generated XSLT -->
<map:match pattern="asserts1.xsl">
  <map:generate src="asserts1.sch"/>
  <map:transform src="skeleton1-5.xsl"/>
  <map:transform src="store.xsl">
      <map:parameter name="file" value="asserts1.xsl"/>
      <map:parameter name="dir" value="."/>
  <map:transform type="write-source"/>
  <map:serialize type="xml"/>

(see below for the source code for store.xsl)

Unfortunately, the Schematron skeleton puts out plain
text messages so the output from data1.xml isn't well-formed
XML.  What I wanted was a series of applicable 
Schematron messages as XML output.  So, I altered
the skeleton somewhat and now I works!

My alterations to the skeleton were pretty simple:

(1)  Add the following template:

<xsl:template match="sch:error | error" mode="text">
     <xsl:copy-of select="."/>

(2) Wrap a <sch:results> around the "/" template:

  <axsl:template match="/">
          <xsl:call-template name="process-root">

Finally, you must wrap all messages in the .sch file with
<sch:error>...</sch:error> as follows:

<sch:schema xmlns:sch="">
<sch:assert test="(@Title = 'Mr' and Sex = 'Male') or @Title != 'Mr'">
  <sch:error>If the Title is "Mr" then the sex of the person must be "Male".</sch:error>


-- jack

(The XSLT file "store.xsl" is my own brew to wrap an
element around the input source for use by the subsequent

<?xml version="1.0" encoding="UTF-8"?>
<!-- CVS: $Id: store.xsl,v 1.1 2002/12/16 11:04:11 callahan Exp $ -->

<xsl:stylesheet version="1.0" xmlns:xsl="">

<xsl:param name="file" select="'foo'"/>
<xsl:param name="dir" select="'foo'"/>

<xsl:template match="/">
    <source:write xmlns:source="">
 <source:source><xsl:value-of select="$dir"/>/<xsl:value-of select="$file"/></source:source>
     <xsl:copy-of select="."/>


Please check that your question  has not already been answered in the
FAQ before posting.     <>

To unsubscribe, e-mail:     <>
For additional commands, e-mail:   <>

View raw message