schema aware schematron in xsd

This should cover W3C XML Schema, Relax NG and DTD related problems.
Posts: 228
Location: Hamburg/Germany

schema aware schematron in xsd

Mon Mar 02, 2015 9:37 am


I have added soem schematron rules within my xsd. Now with growing complexity it appears that I use the same element name twice and it might happen that a schematron rules matches the second element as well which it shouldn't. Now my idea is to use schema-element or element(*, myType) as pattern to ensure I match only the specific element.

Of course this requires an xsl:import-schema and i made it work within a schematron file. However, I can't get it work with xsd embedded scheamtron. I keep getting the message
XPST0008 XSLT Pattern syntax error at char 11 on line 26 in {element(*, digitsType)}: No schema has been imported for namespace ''

my test schema looks like this:

Code: Select all

   xmlns:xs   = ""
   xmlns:sch   = ""
   xmlns:xsl   = ""
         <xsl:import-schema schema-location="Schema.xsd"/>
   <xs:element name="root">
            <xs:element name="digits" type="digitsType" maxOccurs="unbounded"/>
   <xs:simpleType name="digitsType">
               <!--<sch:rule context="digits">-->
               <sch:rule context="element(*, digitsType)">
                  <sch:assert test="matches(text(), '^[0-9]+$')">
                     The <sch:value-of select="name()"/>-element must contain only digits. (xsd)
      <xs:restriction base="xs:string"/>

I guess when extracting the schematron code from the xsd it only considers sch:pattern and simply ignores the xsl:import-schema. Is there any way to make this work? (I already tried to use sch:include but this seems to be ignored as well.)
Posts: 228
Location: Hamburg/Germany

Re: schema aware schematron in xsd

Sun Mar 29, 2015 11:18 am

I managed to make it work by modifying the schematron xslt scripts. If someone is interested I'd gladly share the code. (Some more modifications were neccessary.)

It might as well me a nice feature to add "schema aware" as a schematron configuration parameter to oxygen.

Site Admin
Posts: 2100

Re: schema aware schematron in xsd

Thu Apr 02, 2015 4:49 pm

Hi Patrick,

I think this comes down to copying the embedded XSLT together with the embedded Schematron when the Schematron rules are extracted from the XSD or Relax NG schema.
We plan to support this as well - but it will work only if allowForeign is set to true, otherwise the foreign elements (other than Schematron) will be discarded when the Schematron schema is converted to XSLT.

Best Regards,
George Cristian Bina

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests