Schematron与兄弟姐妹的坏模式

时间:2016-06-06 13:06:15

标签: xml xslt schematron

嗨我有这样的XML:

<databaza>
<dvd>
    <movie>
        <number_of_character>2</number_of_character>
        <character>
            <character_id>1</character_id>
        </character>
        <character>
            <character_id>2</character_id>
        </character>
    </movie>
    <movie>
        <number_of_character>4</number_of_character>
        <character>
            <character_id>1</character_id>
            </character>
        <character>
            <character_id>2</character_id>
            </character>
        <character>
            <character_id>3</character_id>
            </character>
        <character>
            <character_id>4</character_id>
            </character>
    </movie>
</dvd>
</databaza>

和schematron代码:

    <pattern>
    <rule context="databaza/dvd/movie/character">
        <assert test="character_id &lt;= ../number_of_character">
         Element "character_id" is grater than element "number_of_character".</assert>
    </rule>
</pattern>

<pattern>
    <rule context="databaza/dvd/movie/character">
        <assert test="current()/character_id &lt; following-sibling::*[1]/character_id"> 
         Bad order. </assert>
    </rule>
</pattern>

我遇到了没有其他兄弟的部分的问题。 你能帮助我吗 ?

我使用了这两种模式,因为我需要从1到最大的顺序<character_id>(元素<number_of_character>)所以如果你有更好的模式,说数字必须按这些顺序,请写对我来说。

1 个答案:

答案 0 :(得分:0)

我建议您修改上一个assert

<assert test="(current()/character_id &lt; following-sibling::*[1]/character_id) 
               or not(following-sibling::*)"> 
            Bad order. </assert>

这样规则就是'#34;中立&#34;对于最后一个<character>兄弟姐妹。