本文介绍了使用Schematron和xsltproc验证XSD架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难验证与Schematron结合使用的SXD模式.

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

按照此指南中所述的步骤,我在在XSD文档中的标签,如下所示:

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"/>

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

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

问题出在脚本上:该脚本希望接收Schematron架构,并且您为其提供了带有嵌入式规则的XML架构,这是另一种野兽.

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.

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

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.

您还可以使用xmllint(libxml)根据XML Schema来验证文档,这是另一种操作.

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

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

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

或者,您可以使用本机支持架构中的嵌入式Schematron规则的实现,也可以使用诸如 oXygen .

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

这篇关于使用Schematron和xsltproc验证XSD架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 11:47