Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 检查同级元素中的重复属性数据-Schematron_Validation_Xpath_Schematron - Fatal编程技术网

Validation 检查同级元素中的重复属性数据-Schematron

Validation 检查同级元素中的重复属性数据-Schematron,validation,xpath,schematron,Validation,Xpath,Schematron,我正在尝试在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="a

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


有什么想法吗?

我不知道Schematron,但如果您能够使用XPath 2.0(这是可能的),它将派上用场

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的了解还不够,无法做到这一点。

我会在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>
您还可以在此处添加对条形图属性的检查