Hi,

I haven't worked on Schematron for quite a while now, but you can extract
the Schematron rules from the XSD schema quite easily with XSLT, before
compiling the resulting Schemtron schema to XSLT.  The following stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xs="http://www.w3.org/2001/XMLSchema";
                xmlns:sch="http://purl.oclc.org/dsdl/schematron";
                version="2.0">

   <xsl:template match="node()">
      <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="xs:schema">
      <sch:schema queryBinding="xslt2">
         <xsl:apply-templates/>
      </sch:schema>
   </xsl:template>

   <xsl:template match="sch:*">
      <xsl:copy-of select="."/>
   </xsl:template>

</xsl:stylesheet>

when applied to:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
           xmlns:sch="http://purl.oclc.org/dsdl/schematron";>
   <xs:element name="elem" type="xs:string">
      <xs:annotation>
         <xs:appinfo>
            <sch:pattern name="Foo bar">
               <sch:rule context="elem">
                  <sch:assert test="...">...</sch:assert>
               </sch:rule>
            </sch:pattern>
         </xs:appinfo>
      </xs:annotation>
   </xs:element>
</xs:schema>

generates the following (ready to be used as any Schematron schema):

<sch:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
            xmlns:sch="http://purl.oclc.org/dsdl/schematron";
            queryBinding="xslt2">

   <sch:pattern name="Foo bar">
      <sch:rule context="elem">
         <sch:assert test="...">...</sch:assert>
      </sch:rule>
   </sch:pattern>

</sch:schema>

Regards,

-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/



On 10 May 2016 at 12:57, shabana khan wrote:

> Hi Erik,
>
> Thanks for your input.
>
> The requirement is like we need to do 2-step validation :
> 1. Validation against the schema which we have in place.
> 2. Validation against the schematron.
>
> Currently it is being validated against the schema but it is not checking
> for the schematron part present in the schema file. So, we are planning to
> compile it into xslt and then validate the document.
>
> Thanks and Regards,
> Shabana Khan
> LinkedIn <https://in.linkedin.com/pub/shabana-khan/40/229/454>
>
>
>
>
> On Tue, May 10, 2016 at 1:14 AM, Erik Hennum <erik.hen...@marklogic.com>
> wrote:
>
>> Hi, Shabana:
>>
>> > We need to compile our XSD file into XSLT so that we can use a compiled
>> version for validation
>>
>> Is there a reason you can't use the MarkLogic builtin support for
>> validating a document
>> against an XSD?
>>
>> If you insert an XML Schema into the schema database for your content
>> database and
>> restart the server, you should be able to validate documents against the
>> schema using
>> either an XQuery validate expression:
>>
>>     https://www.w3.org/TR/xquery-30/#id-validate
>>
>> or the MarkLogic validate function:
>>
>>     http://docs.marklogic.com/xdmp:validate
>>
>> The builtin validation will almost certainly be faster than an XSLT
>> invocation.
>>
>> The other question is whether your Schematron compiler supports compiling
>> an XSD.
>>
>>
>> Hoping that helps,
>>
>>
>> Erik Hennum
>>
>>
>> ------------------------------
>> *From:* general-boun...@developer.marklogic.com [
>> general-boun...@developer.marklogic.com] on behalf of shabana khan [
>> shabana.0...@gmail.com]
>> *Sent:* Monday, May 09, 2016 7:18 AM
>> *To:* General@developer.marklogic.com
>> *Subject:* [MarkLogic Dev General] Regarding compilation of schema for
>> validation.
>>
>> Hi All,
>>
>> We need to compile our XSD file into XSLT so that we can use a compiled
>> version for validation
>> When we use *sch:compile-schema($schematron) *and give schematron as
>> input it successfully generates the XSLT.
>> But we have as input an XSD which comprises both schematron part and
>> schema part like we do have *pattern elements *and *schema elements *as
>> well*.*
>> We are getting errors :
>> *sc:compile-schema($schematron) -- Invalid coercion*
>>
>> Can anyone give suggestion regarding this.
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> General mailing list
>> General@developer.marklogic.com
>> Manage your subscription at:
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to