2017-09-05 3 views
0

タイトルで説明したように、XML兄弟要素の重複した属性データをチェックする方法を探したい。複数の属性を持つ重複データが兄弟要素にあるかどうかを調べる - Schematron

私はすでに同様の質問 [ここ] 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> 

私はZDXXH属性を持つ一意である<test>要素を必要としています。 testのすべての兄弟要素は、ZDXXHの両方の属性が同時に別のテストと等しくないこと、またはSchemaTronの検証エラーが発生することを満たす必要があります。

私はそれが上記の状況で正常に動作しますが、最後のtest要素に

<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> 

下回る状況では動作しない、

<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> 

をこの方法を試してみました、XH="4"は、検証を発射します私が最後の行を変更した場合、 <test ZDX="b" XH="4" ps="qwrew"/>から<test ZDX="b" XH="7" ps="qwrew"/>になると、それは一意になり、検証を起動しません。

したがって、どのSchematron TestフレーズでZDXXHの両方をチェックするにはどうすればよいですか?

答えて

0

これは動作するはず

<sch:pattern id="duplicate-attribute" abstract="true"> 
    <sch:rule context="$element"> 
     <sch:report test="@$attribute = following-sibling::$element/@$attribute 
      or @$attribute = preceding-sibling::$element/@$attribute"> 
      Duplicate '$attribute' attribute value found 
     </sch:report> 
    </sch:rule> 
</sch:pattern> 

<sch:pattern is-a="duplicate-attribute"> 
    <sch:param name="element" value="test"/> 
    <sch:param name="attribute" value="XH"/> 
</sch:pattern> 

<sch:pattern is-a="duplicate-attribute"> 
    <sch:param name="element" value="test"/> 
    <sch:param name="attribute" value="ZDX"/> 
</sch:pattern> 
関連する問題