2

我在验证与 Schematron 结合的 SXD 模式时遇到了困难。

按照本指南中描述的步骤,我<xs:appinfo>在 XSD 文档中的标记之间合并了 schematron,如下所示:

<?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>

该文档应该测试(或验证)该文档

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

使用 schematron页面上列出的简单的基于 xsltproc 的脚本。不幸的是,我在脚本的最后一步收到以下错误消息。

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

我很感激帮助找出这个错误的原因。

4

1 回答 1

3

您的架构是正确的,并且做了它应该做的事情......

问题出在脚本上:这个脚本期望接收一个 Schematron 模式,而你给它一个带有嵌入规则的 XML 模式,这是一种不同的野兽。

要进行验证,您需要运行第一个转换,该转换将从 XML Schema 中提取 Schematron 并对这个结果运行 validate。

您还可以使用 xmllint (libxml) 根据 XML Schema 验证文档,这是一种不同的操作。

为此,您可以将脚本下载ExtractSchFromXSD.xsl更改为:

#!/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

或者,您可以使用本机支持模式中嵌入的 Schematron 规则的实现,或者使用诸如oXygen 之类的工具。

于 2012-05-19T15:09:43.693 回答