我正在尝试使用
验证带有抽象规则的简单schematron给出的XML是教程中的简化示例Schematron文件:
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
<sch:title>This is an example schema for the Building Projects XML language.</sch:title>
<sch:pattern id="construction">
<sch:rule context="house">
<sch:assert test="count(wall) = 4">A house should have 4 walls</sch:assert>
<sch:report test="not(roof)">The house is incomplete, it still needs a roof</sch:report>
<sch:assert test="builder">An incomplete house must have
a builder assigned to it</sch:assert>
<sch:assert test="not(owner)">An incomplete house cannot have an owner</sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern id="completed">
<sch:rule context="house">
<sch:assert test="count(wall) = 4">A house should have 4 walls</sch:assert>
<sch:report test="roof">The house is incomplete, it still needs a roof</sch:report>
<sch:assert test="owner">An incomplete house must have an owner</sch:assert>
<sch:assert test="not(builder)">An incomplete house doesn't need a builder</sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern id="admin">
<sch:rule abstract="true" id="nameChecks">
<sch:assert test="firstname">A <name/> element must have a first name</sch:assert>
<sch:assert test="lastname">A <name/> element must have a last name</sch:assert>
</sch:rule>
<sch:rule context="builder">
<sch:extends rule="nameChecks"></sch:extends>
<sch:assert test="certification">A <name/> must be certified</sch:assert>
</sch:rule>
<sch:rule context="owner">
<sch:extends rule="nameChecks"></sch:extends>
<sch:assert test="telephone">An <name/> must have a telephone</sch:assert>
</sch:rule>
<sch:rule context="certification">
<sch:assert test="@number">Certification numbers must be recorded in the number attribute</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
我现在做的是:
xmllint --noout --schematron mySchema.schema ToVerify.xml
我收到错误消息:
mySchema.schema:26:元素规则:架构解析器错误:规则没有上下文属性 - &GT;这是:
mySchema.schema:32:element extends:架构解析器错误:期望断言或报表元素而不是扩展 - &GT;这是: mySchema.schema:36:元素扩展:模式解析器错误:期望断言或报告元素而不是扩展 Schematron mySchema.schema无法编译
因为这只是像#34; abstract&#34;这样的新问题。规则(抽象模式确实有用......)我假设libxml版本没有能力将它转换/解析/预处理成它可以处理的东西。
所以我找到了扩展抽象元素的预处理器: iso_abstract_expand.xsl(对于iso Schematron xslt2)
但xsltproc不会使用
预处理文件xsltproc iso_abstract_expand.xsl mySchema.schema > somefile.schema
所以我的问题是:
我很抱歉,如果这一切听起来很混乱,但我发现了大量关于使用抽象元素的提示,但他们从未提及如何测试它们/使用xmllint编译它们。