cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <jtaca...@xa.lg.ehu.es>
Subject Re: Schematron transform in a Cocoon pipeline
Date Wed, 22 Jan 2003 10:27:10 GMT

Jack,

I also use it to validate uploaded documents. First, when cocoon 
receives the document, I applied to it the first validation step with 
the parser (inside the generator): the parser will check that the 
document is well formed and valid according to a certain W3C XML 
Schema. But there are some verifications which can't be done with the 
schema, so for them I use the Schematron which is embedded in the W3C 
Schema.

<map:match pattern="validationRequest">
    <map:generate src="forms/sendDocument.xml"/>
    <map:transform src="stylesheets/wizard2html.xsl"/>
    <map:transform src="stylesheets/xmlform2html.xsl"/>
    <map:serialize/>
</map:match>

<map:match pattern="validationResponse">
    <map:generate type="myStream">
        <map:parameter name="file-name" value="document"/>
        <map:parameter name="validation" value="true"/>
    </map:generate>
    <map:transform src="cocoon:/schematron2compiledSchematron"/>
    <map:transform src="stylesheets/schematronError2error.xsl"/>
    <map:transform src="stylesheets/error2html.xsl"/>
    <map:serialize/>
</map:match>

<map:match pattern="schematron2compiledSchematron">
    <map:generate src="schemas/berta.xsd"/>
    <map:transform type="xalan" src="stylesheets/getSchematron.xsl"/>
    <map:transform type="xalan" src="stylesheets/skeleton1-5.xsl"/>
    <map:serialize type="xml"/>
</map:match>

Now, as Jeff Turner suggested in http://marc.theaimsgroup.com/?l=xml-
cocoon-users&m=104308827116656&w=2 , I'm thinking on moving the W3C 
schemaValidation from the generator to a transformer 
(ValidationTransformer), using JARV.

Oskar

> Oskar,
> 
> Excellent suggestion.  The XPATH of the error would be very useful for
> debugging.  What applications of Schematron have you done within 
Cocoon?
> So far, I'm using it to validate uploaded documents.
> 
> -- jack
> 
> > 
> > Hi Jack,
> > 
> > I have done the same to validate an XML document with an 
schematron. I think
> > that it would be also useful to get the XPATH path of the errors in 
the XML
> > output. The template which does this is done in skeleton1-5 
(<axsl:template
> > match="*|@*" mode="schematron-get-full-path">); so you have to call 
it from
> > the assert template:
> > 
> > <xsl:template match="sch:assert | assert">
> >     <xsl:if test="not(@test)">
> >         <xsl:message>Markup Error: no test attribute in
> > <assert></xsl:message>
> >     </xsl:if>
> >     <axsl:choose>
> >         <axsl:when test="{@test}"/>
> >         <axsl:otherwise>
> >             <error> <!--my xml output-->
> >                 <message> <!--my xml output-->
> >                     <xsl:call-template name="process-assert">
> >                     <xsl:with-param name="role" select="@role"/>
> >                     <xsl:with-param name="id" select="@id"/>
> >                     <xsl:with-param name="test"
> > select="normalize-space(@test)" />
> >                     <xsl:with-param name="icon" select="@icon"/>
> >                     <xsl:with-param name="subject" 
select="@subject"/>
> >                     <xsl:with-param name="diagnostics"
> > select="@diagnostics"/>
> >                     </xsl:call-template>
> >                 </message>
> >                 <location> <!--my xml output-->
> >                     <axsl:apply-templates mode="schematron-get-full-
path"
> > select="self::*"/> <!--XPATH path of the error-->
> >                 </location>
> >             </error>
> >          </axsl:otherwise>
> >     </axsl:choose>
> > </xsl:template>
> > 
> > Oskar
> > 
> > ----- Original Message -----
> > From: "John R. Callahan" <jcallahan@sphere.com>
> > To: <cocoon-users@xml.apache.org>
> > Sent: Tuesday, January 21, 2003 9:58 PM
> > Subject: Schematron transform in a Cocoon pipeline
> > 
> > 
> > > 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
> > > data:
> > >
> > > <map:match pattern="*.xml">
> > >   <map:generate src="{1}.xml"/>
> > >   <map:transform src="asserts1.xsl"/>
> > >   <map:serialize type="xml"/>
> > > </map:match>
> > >
> > > <!-- 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>
> > >   <map:transform type="write-source"/>
> > >   <map:serialize type="xml"/>
> > > </map:match>
> > >
> > > (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="."/>
> > > </xsl:template>
> > >
> > > (2) Wrap a <sch:results> around the "/" template:
> > >
> > >   <axsl:template match="/">
> > >       <sch:results>
> > >           <xsl:call-template name="process-root">
> > >             ...
> > >           </xsl:call-template>
> > >       </sch:results>
> > >   </axsl:template>
> > >
> > > Finally, you must wrap all messages in the .sch file with
> > > <sch:error>...</sch:error> as follows:
> > >
> > > <sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
> > > ...
> > > <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>
> > > </sch:assert>
> > > ...
> > > </sch:schema>
> > >
> > > Enjoy!
> > >
> > > -- jack
> > >
> > >
> > > (The XSLT file "store.xsl" is my own brew to wrap an
> > > element around the input source for use by the subsequent
> > > SourceWriterTransformer:
> > >
> > > <?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="http://www.w3.org/1999/XSL/Transform">
> > >
> > > <xsl:param name="file" select="'foo'"/>
> > > <xsl:param name="dir" select="'foo'"/>
> > >
> > > <xsl:template match="/">
> > >     <source:write 
xmlns:source="http://apache.org/cocoon/source/1.0">
> > >  <source:source><xsl:value-of select="$dir"/>/<xsl:value-of
> > select="$file"/></source:source>
> > >  <source:fragment>
> > >      <xsl:copy-of select="."/>
> > >  </source:fragment>
> > >     </source:write>
> > > </xsl:template>
> > >
> > > </xsl:stylesheet>
> > > )
> > >
> > >
> > >
> > > ------------------------------------------------------------------
---
> > > Please check that your question  has not already been answered in 
the
> > > FAQ before posting.     
<http://xml.apache.org/cocoon/faq/index.html>
> > >
> > > To unsubscribe, e-mail:     <cocoon-users-
unsubscribe@xml.apache.org>
> > > For additional commands, e-mail:   <cocoon-users-
help@xml.apache.org>
> > >
> > 
> > 
> > --------------------------------------------------------------------
-
> > Please check that your question  has not already been answered in 
the
> > FAQ before posting.     
<http://xml.apache.org/cocoon/faq/index.html>
> > 
> > To unsubscribe, e-mail:     <cocoon-users-
unsubscribe@xml.apache.org>
> > For additional commands, e-mail:   <cocoon-users-
help@xml.apache.org>
> > 
> 
> 
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
> For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>
> 
> 






---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message