【问题标题】:Check for duplicated attribute data in sibling elements - Schematron检查同级元素中的重复属性数据 - Schematron
【发布时间】:2013-12-16 18:35:56
【问题描述】:

我正在尝试在 Schematron 中编写一个检查,以确保没有元素包含重复的属性数据。这些元素位于 XML 文档中的特定位置,我有定位它们的 XPATH。

例如:

应该失败,因为它有重复的 foo 和 bar 属性值。

<id foo="test1" bar="abc" />
<id foo="test1" bar="abc" /> 

这应该通过,因为 foo 属性不一样。

<id foo="test1" bar="abc" /> 
<id foo="test2" bar="abc" /> 

我不确定这对于 Schematron 是否过于复杂。

有什么想法吗?

【问题讨论】:

    标签: validation xpath schematron


    【解决方案1】:

    我不知道 Schematron,但如果您能够使用 XPath 2.0(这可能是at least with some implementations),deep-equal($val1, $val2) 会派上用场。

    not(deep-equal(<id foo="test1" bar="abc" />, <id foo="test1" bar="abc" />)) (: false :)
    not(deep-equal(<id foo="test1" bar="abc" />, <id foo="test2" bar="abc" />)) (: true :)
    

    如果没有,应该有一个使用 XSLT 1.0 的解决方案,但您必须自己构建递归比较(而且我对 XSLT 的了解不够透彻)。

    【讨论】:

      【解决方案2】:

      我会在 Schematron 中这样做(通过 XML ValidatorBuddy 检查):

      <iso:pattern id="unique name attributes">
        <iso:rule context="id">
          <iso:assert test="count(id) = count(id[not(@foo=preceding-sibling::person/@foo)])">
           Not all foo attributes of the id elements are unique
          </iso:assert>
       </iso:rule>
      </iso:pattern>
      

      您还可以在此处添加对 bar 属性的检查。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-19
        • 1970-01-01
        • 2013-06-28
        • 2010-11-22
        • 1970-01-01
        相关资源
        最近更新 更多