0

我正在尝试在 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 是否太复杂。

有什么想法吗?

4

2 回答 2

0

我不知道 Schematron,但如果您能够使用 XPath 2.0(至少在某些实现中是可能的),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 的了解还不够好,无法这样做)。

于 2013-12-16T23:14:56.490 回答
0

我会在 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 属性的检查。

于 2013-12-17T12:22:42.460 回答