0
如標題所述,我想找到一種方法來檢查XML同級元素中的重複屬性數據。檢查同級元素中具有多個屬性的重複數據 - Schematron
我已經知道了類似的問題 [here] 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
屬性。 測試的所有兄弟元素都應該滿足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"/>
更改爲<test ZDX="b" XH="7" ps="qwrew"/>
,它會變成唯一的,並且不會觸發驗證。
那麼,如何在一個Schematron測試短語中檢查ZDX
和XH
?