【发布时间】:2017-09-05 08:23:14
【问题描述】:
如标题所述,我想找到一种方法来检查 XML 兄弟元素中的重复属性数据。
我已经知道类似的问题 [这里]Check for duplicated attribute data in sibling elements - Schematron,我试过了,对我没用。
我的情况是检查多个属性。
<root>
<test ZDX="a" XH="1" ps="sdf"/>
<test ZDX="a" XH="2" ps="dfg"/>
<test ZDX="a" XH="3" ps="hfgh"/>
<test ZDX="a" XH="2" ps="ertewr"/><!--same with the 2nd line-->
</root>
我需要 <test> 元素与 ZDX 和 XH 属性是唯一的。
test 的所有兄弟元素都应该满足ZDX 和XH 属性不能同时等于另一个测试,否则会触发 SchemaTron 验证错误。
我试过这种方法,
<rule context="/root/test">
<assert test="count(self::test) = count(self::test[not(@ZDX=preceding-sibling::test/@ZDX and @XH=preceding-sibling::test/@XH)])">
test is not unique
</assert>
</rule>
上面的情况很好用,下面的情况就不行了
<root>
<test ZDX="a" XH="1" ps="sdf"/>
<test ZDX="a" XH="2" ps="dfg"/>
<test ZDX="a" XH="3" ps="hfgh"/>
<test ZDX="a" XH="4" ps="ertewr"/>
<test ZDX="b" XH="5" ps="ndmfj"/>
<test ZDX="b" XH="6" ps="yuoi"/>
<test ZDX="b" XH="4" ps="qwrew"/><!--conflict with the 4th line-->
</root>
在最后一个 test 元素中,如果我更改最后一行,XH="4" 将触发验证
<test ZDX="b" XH="4" ps="qwrew"/>to <test ZDX="b" XH="7" ps="qwrew"/>,变成唯一的,不会触发验证。
那么,我如何在一个 Schematron 测试短语中同时检查 ZDX 和 XH?
【问题讨论】:
标签: xml validation schematron