本文介绍了检查同级元素中的重复属性数据-Schematron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to write a check in Schematron that will ensure no elements contain duplicated attribute data. These elements are at a specific location in the XML document, I have the XPATH that locates them.

例如:

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

should fail because it has duplicate foo and bar attribute values.

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

这应该通过,因为foo属性不相同.

This should pass as the foo attributes are not the same.

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

我不确定这对于Schematron是否太复杂了.

I'm not sure if this is too complicated for Schematron.

有什么想法吗?

推荐答案

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

I would do it this way in Schematron (checked with 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属性的检查.

You can also add a check for the bar attribute here.

这篇关于检查同级元素中的重复属性数据-Schematron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:55