Page 1 of 1

How to get embedded Schematron to work?

Posted: Thu Apr 09, 2009 5:09 pm
by PetrolDave
I've been working on a XSD file for a while and realised today that I need to embed Schematron to do some of the checks needed. I've followed the (few) examples I can find but the Schemtron doesn't seem to run.

Here's a segment of the xsd:

<!-- ?xml version="1.0" encoding="ISO-8859-1"? -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sch="http://www.ascc.net/xml/Schematron"
elementFormDefault="qualified">

<!-- Setup Schematron -->
<xsd:annotation>
<xsd:appinfo>
<sch:title>Schematron validation</sch:title>
<sch:ns prefix="v" uri="sample.xsd"/>
</xsd:appinfo>
</xsd:annotation>

<!-- Define the root and the uniqueness rules -->
<xsd:element name="root" type="RootType">

<!-- Define Schematron pattern(s) -->
<xsd:annotation>
<xsd:appinfo>
<sch:pattern name="Check Trunk Card names in Trunks">
<sch:rule context="v:.//trunk_card">
<sch:assert test="v:name == v:trunk/trunk_card_name"
diagnostics="TrunkCardName">
must match
</sch:assert>
</sch:rule>
</sch:pattern>
<sch:diagnostic id="TrunkCardName">
Error! does not match
trunk_card[]/name =
<sch:value-of select="v:name"/>
trunk_card[]/trunk[]/trunk_card_name =
<sch:value-of select="v:trunk/trunk_card_name"/>
</sch:diagnostic>
</xsd:appinfo>
</xsd:annotation>
...
</xsd:/element>
</xsd:schema>

And the xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?oxygen SCHSchema="sample.xsd"?>
...
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sample.xsd">
<trunk_card enabled="Yes">
<name>Trunk Card 2</name>
<trunk enabled="Yes">
<name>First Trunk</name>
<trunk_card_name>Trunk Card 1</trunk_card_name>
<trunk_number>0</trunk_number>
</trunk>
<trunk enabled="Yes">
<name>Second Trunk</name>
<trunk_card_name>Trunk Card 1</trunk_card_name>
<trunk_number>7</trunk_number>
</trunk>
</trunk_card>
...
</root>

The xml has the trunk_card/trunk/trunk_card_name elements deliberately set to be different to the trunk_card/name parent - but the Schematron doesn't report the error???

I'm a complete novice to Schematron, so be kind if I'm doing something silly!

Re: How to get embedded Schematron to work?

Posted: Thu Apr 09, 2009 5:17 pm
by PetrolDave
I think I might have just answered my own question...

I was using xmlns:sch="http://www.ascc.net/xml/Schematron" instead of xmlns:sch="http://purl.oclc.org/dsdl/schematron"

Doh!!!

Re: How to get embedded Schematron to work?

Posted: Thu Apr 09, 2009 5:24 pm
by PetrolDave
What's wrong with this line?

<sch:rule context=".//v:trunk_card">

I've tried v:.//trunk_card as well as .//v:trunk_card

Sorry for all the questions!

Re: How to get embedded Schematron to work?

Posted: Thu Apr 09, 2009 5:59 pm
by sorin_ristache
Hello,

v:.//trunk_card is not a valid expression. The expression specified in the context attribute should be relative to the element in which that sch:rule is used.

You did not post a working sample so I cannot offer more help.


Regards,
Sorin

Re: How to get embedded Schematron to work?

Posted: Wed Aug 19, 2009 2:07 am
by shudson310
I'm trying to validate a file using Schematron, but am getting a bunch of errors reported on the schematron file. It works in jnvdl, but can't seem to get it working in oXygen? Does oXygen support schematron like:

<?xml version="1.0"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:regexp="http://exslt.org/regular-expressions"
queryBinding="xslt2"
>
<title>Grammar (Schematron Layer)</title>

<ns uri="http://www.w3.org/1998/Math/MathML" prefix="m"/>
<ns uri="http://www.w3.org/2005/xpath-functions" prefix="fn"/>
<ns uri="http://exslt.org/regular-expressions" prefix="regexp"/>

Some errors I get are:

SystemID: C:\projects\rules.sch
Engine name: oNVDL
Severity: error
Description: Error in expression foo:bar[@type eq 'baz']: expected "]", found "<name>"

I think that's a valid expression? (assuming the namespaces are all declared).

Thanks,

--Scott

Re: How to get embedded Schematron to work?

Posted: Wed Aug 19, 2009 9:50 am
by george
Hi Scott,

oXygen supports pre ISO Schematron and ISO Schematron, both as standalone schemas and embedded in XML Schema or Relax NG. However, it seems you are trying to use that from NVDL and oNVDL does not support ISO Schematron.

I integrated the NVDL support from oNVDL into the new jing-trang project where support for ISO Schematron is high on the todo list:
http://code.google.com/p/jing-trang/issues/detail?id=23

oXygen starting with its next release will integrate the new jing-trang instead of oNVDL so as soon as that will be implemented it will be available also from within oXygen.

Best Regards,
George