質問

I'm having difficulty validating an SXD schema combined with Schematron.

Following the steps described in this guide I've incorporated schematron between the <xs:appinfo> tags in an XSD document as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="Test">

        <xs:annotation>
            <xs:appinfo>
                <sch:pattern name="Testing schematron" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
                    <sch:rule context="Test">
                        <sch:assert test="@Attribute1">Attribute 1 exists</sch:assert>
                    </sch:rule>
                </sch:pattern>
            </xs:appinfo>
        </xs:annotation>

        <xs:complexType> 
            <xs:attribute name="Attribute1" type="xs:string" use="optional"/>
            <xs:attribute name="Attribute2" type="xs:string" use="optional"/>
        </xs:complexType>
    </xs:element>

</xs:schema>

This document is supposed to test (or validate) the document

<?xml version="1.0" encoding="ISO-8859-1"?>
<Test Attribute1="attr1"/>

using the simple xsltproc-based script listed on the schematron page. Unfortunately, I'm getting the following error message at the last step of the script.

step3.xsl:13: parser error : Extra content at the end of the document
plates select="*|comment()|processing-instruction()" mode="M0"/></axsl:template>
                                                                               ^
cannot parse step3.xsl

I'd appreciate help figuring out the cause of this error.

役に立ちましたか?

解決

Your schema is correct and does what it is meant to do...

The issue is with the script: this script expects to receive a Schematron schema and you give it a XML Schema with embedded rules which is a different kind of beast.

To do your validation, you need to run a first transformation that will extract the Schematron from XML Schema and run validate on this result.

And you could also use xmllint (libxml) to validate the document against the XML Schema which is a different operation.

To do, you can change download ExtractSchFromXSD.xsl your script to:

#!/bin/bash

echo XSD validation
xmllint -schema $1 $2

echo Step0 ...
xsltproc ExtractSchFromXSD.xsl $1 > schema.sch

echo Step1 ...
xsltproc iso_dsdl_include.xsl schema.sch > step1.xsl

echo Step2 ...
xsltproc iso_abstract_expand.xsl step1.xsl > step2.xsl

echo Step3 ...
xsltproc iso_svrl_for_xslt1.xsl step2.xsl > step3.xsl

echo Validation ...
xsltproc step3.xsl $2 | tee result.svrl

Alternatively, you could use an implementation that natively supports embedded Schematron rules in schemas or a tool such as oXygen.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top