【问题标题】:Schematron validation and uniquenessSchematron 验证和唯一性
【发布时间】:2010-09-24 08:08:07
【问题描述】:

我正在尝试编写一些 Schematron 规则,其中一个应该检查元素是否在父元素的范围内是唯一的。所以我有一个示例 xml 结构:

<abc>
  <elem id="qw0">
    <a>1</a>
    <a>2</a>
    <a>3</a>
  </elem>
  <elem id="qw1">
    <a>1</a>
    <a>2</a>
    <a>3</a>
    <a>3</a>
  </elem>
</abc>

我的规则应该检查每个元素的“a”元素是否是唯一的。在此特定示例中,对于具有 id="qw1" 的 elem,有两个值为“3”的元素“a”。这是不允许的。

到目前为止,我已经得出了这种规则:

<iso:pattern id="doc.abc">
  <iso:title>checking ABC</iso:title>
  <iso:rule context="elem">
    <iso:assert test="count(a[. = current()]) = 1">TACs should be unique.</iso:assert>
  </iso:rule>
</iso:pattern>

但这不起作用,因为它会查看整个文档,而不仅仅是 elem 的直接子代。

【问题讨论】:

    标签: xml xml-validation schematron


    【解决方案1】:

    如果您正在使用带有底层 XSLT/XPath 2.0 引擎的 Schematron 处理器,并且希望将规则的上下文作为您可以使用的 元素:

    价值观不同

    【讨论】:

      【解决方案2】:

      我发现这可以通过以下规则解决:

      <iso:pattern id="doc.abc">
        <iso:title>checking ABC</iso:title>
        <iso:rule context="a">
          <iso:assert test="count(parent::node()/a[. = current()) = 1">TACs should be unique.</iso:assert>
        </iso:rule>
      </iso:pattern>
      

      但这会触发每个 a 元素的规则。

      为每个 elem 触发它会更优雅,而不是 a。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-30
        • 2020-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多