How to get embedded Schematron to work?
Posted: Thu Apr 09, 2009 5:09 pm
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!
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!