纷繁的 XML Schema 技术:基于规则的语言[6]
[入库:2005年8月18日] [更新:2007年3月25日]
</sch:rule>
some notes about rules:
一些关于规则的注意事项是:
- the context of a rule cannot be set on an attribute.
- the order in which the tests (report and assert elements) are performed is not guaranteed and the sequence of tests stops after the first failure.
- 规则的上下文不能设置为属性。
- 测试(report 和 assert 元素)执行的顺序是不被保证的,而且一系列测试在第一个错误发生的时候终止。.
2.2.3. pattern(s)
pattern elements are sets of rules which are evaluated independently (technically using different modes in the xslt stylesheet generated out of the schematron schema).
pattern 元素是一批独立执行的规则(技术上讲,在 schematron schema 之外是使用 xslt 样式表中的不同 mode 来保证的)。
an example of pattern roughly equivalent to our open xslt schema could be:
一个和我们的开放 xslt schema 相当的例子可能是这样:
<sch:pattern>
<sch:rule context="/">
<sch:assert test="library">
the document element should be 'library'.
</sch:assert>
</sch:rule>
<sch:rule context="library">
<sch:report test="*[not(self::book)]">
the library element should contain only book elements.
</sch:report>
<sch:report test="@*">
the library element should not contain attributes.
</sch:report>
<sch:report test="text()[normalize-space()]">
the library element should not contain attributes.
</sch:report>
</sch:rule>
<sch:rule context="book">
<sch:report test="@*[name() != 'id']">
the book element should not include any attribute other than "id".
</sch:report>
<sch:assert test="@*[namespace-uri() = '']">
the book element should not include any attribute other than "id" (namespace).
</sch:assert>
<sch:report test="@id = preceding-sibling::book/@id">
the book id should be unique.
</sch:report>
</sch:rule>
</sch:pattern>
one of the differences with what we had implemented is that schematron will stop the evaluation of a pattern after the first error found (following the order of the source tree) and if we wanted to be potentially able to raise several errors, we would have to spread our rules within several different patterns.
与我们已经实现的不同之处的一个是 schematron 将在第一个错误发现的时候停止那个 pattern 的执行(按照源代码树的顺序)而且如果你想要能抛出好几个错误,我们需要把规则分散到好几个不同的 pattern 之中去。
2.2.4. schema
finally, the schema element is the document element of a schematron schema and basically include a title and one or more patterns. to implement our rules within separated patterns, we could write:
最后,schema 元素是 schematron schema 的文档元素而且主要包括一个标题以及一个或者多个 pattern。要把我们的 rule 实现于好几个 pattern 之中,我们可以这么写:
<?xml version="1.0" encoding="utf-8"?>
<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
<sch:title>example schematron schema</sch:title>
<sch:pattern>
<sch:rule context="/">
<sch:assert test="library">
the document element should be 'library'.
</sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern>
<sch:rule context="library">
<sch:report test="*[not(self::book)]">
the library element should contain only book elements.
</sch:report>
<sch:report test="@*">
the library element should not contain attributes.
</sch:report>
<sch:report test="text()[normalize-space()]">
the library element should not contain attributes.
</sch:report>
</sch:rule>
</sch:pattern>
<sch:pattern>
<sch:rule context="book">
<sch:report test="@*[name() != 'id']">
the book element should not include any attribute other than "id".
</sch:report>
<sch:assert test="@*[namespace-uri() = '']">
the book element should not include any attribute other than "id" (namespace).
</sch:assert>
<sch:report test="@id = preceding-sibling::book/@id">
the book id should be unique.
</sch:report>
</sch:rule>
</sch:pattern>
本文关键:XML Schematron Rule XSLT
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)