</xsl:template>
</xsl:template>
technically speaking, schematron is a concise formalization of one of the examples which we have seen and generates a xslt transformation which is an open schema (everything which has not been forbidden is allowed) with tests inside the templates.
技术上讲,schematron 是对我们看过的例子中的一个精确的形式化,并且产生的是一个 xslt 转换,它在模板中进行开放 schema (所有没有被禁止的东西都被允许)测试。
that being said, xslt is totally hidden from the schematron user who needs to know the schematron syntax and xpath which is used to express the rules.
也就是,xslt 对 schematron 的用户完全的隐藏起来了。但是他们需要知道 schematron 的语法以及用来表达这些规则的 xpath。
a schematron schema is composed of a set of patterns each pattern including one or more rules and each rule being composed of asserts and reports, however, to present the syntax used by schematron, we'll take it "bottom/up" and start with asserts and reports before seeing how they are associated into rules, patterns and schemas.
schematron schema 由一套 pattern 组成。每个 pattern 包括一个或者多个规则,而且每个规则都由 assert 和 report 组成。然而,为了展示 schematron 使用的语法,我们将反过来,在看它们如何关联到规则,pattern 以及 schema 之中之前,从 assert 和 report 入手。
the "assert" and "report" elements are where the rules are defined in a schematron schema. both carry a "test" attribute which is an xpath expression they differ in a couple of ways:
"assert" 和 "report" 元素是在 schematron schema 中定义规则的地方。都带一个 xpath 表达式的 "test" 属性,它们在几个方面不同:
there are some goodies which we will not cover in this tutorial, but the basic syntax is:
在本教程中有许多好东西是讲不到的,但是基本的语法是这样的:
<sch:assert test="library">
the document element should be 'library'.
</sch:assert>
which raises an error with the corresponding message if there is no "library" element under the context node, or:
如果在上下文节点中没有 "library" 元素,它抛出一个错误和对应的信息,或者:
<sch:report test="@*">
the library element should not contain attributes.
</sch:report>
which raises an error if there is any attribute under the context node.
如果在上下文节点中有任何属性,它抛出一个错误。
in both cases, the context node is set by the "rule" parent element of the report or assert node.
在两种情况中,上下文节点都是由 report 或者 assert 节点的 "rule" 父元素设置的。
schematron rule elements are roughly equivalent to xslt templates and are used to define the context under which a set of assert and report elements will be performed.
schematron rule 元素大体上和 xslt 模板相当并且被用来定义 assert 和report 元素将施加于的上下文。
an example of rule (without bells and whistles) performing the tests done in our open schema on the book element could be:
一个在我们的开放 schema 中对 book 元素执行测试的规则(没有所有的花哨的东西)的例子可能是:
<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>