【问题标题】:Check the attribute of sub-element is with in the range of ancestor:elements attribute检查子元素的属性是否在祖先:元素属性的范围内
【发布时间】:2019-03-28 06:41:46
【问题描述】:

我是 schematron 的新手,并且 试图编写一个断言来验证 @Origin 和 @end of 'tests' 节点的值在 @Origin 和 @end of 'bases' 的范围内

我已经尝试过如下断言,但它不起作用。

<sch:rule context="test">
  <sch:assert test="End[*]/@value &gt; ancestor::bases/bound/End/@value and Origin[*]/@value &lt; ancestor::bases/bound/Origin/@value " >values are within range. </sch:assert>
</sch:rule>
<tests_root>
    <bases>
        <bound x="-276.724" xEnd="-276.193">
            <Origin value="1"/>
            <End value="20"/>
        </bound>
    </bases>
    <tests>
        <test x="-276.724" xEnd="-276.193">
            <Origin value="1"/>
            <End value="2"/>
        </test>
        <test x="-276.193" xEnd="-260.29">
            <Origin value="2"/>
            <End value="5"/>
        </test>
        <test x="-260.29" xEnd="-240.194">
            <Origin value="5"/>
            <End value="10"/>
        </test>
        <test x="-240.194" xEnd="-220.046">
            <Origin value="10"/>
            <End value="19"/>
        </test>
        <test x="-220.046" xEnd="-200.09">
            <Origin value="19"/>
            <End value="20"/>
        </test>
    </tests>
</tests_root>

【问题讨论】:

    标签: xml xsd schematron


    【解决方案1】:

    您的 Schematron 中有些地方不正确,主要是 ancestor::bases/bound/End/@value 不会匹配任何节点,因为 &lt;bases&gt; 不是 &lt;test&gt; 的祖先。使用/tests_root/bases/bound/End/@value 将检索您想要的值。

    然后,您似乎以相反的方式实施了 &lt;sch:assert&gt; 规则(并且不完整,因为您没有测试 Origin 和 End 的绑定值)您宣布了它。提醒:

    • 如果测试不正确,assert 将引发一条消息;
    • 如果测试为真,report 将引发一条消息。

    作为提示,您可以使用&lt;sch:let&gt; 来提高代码的可读性:

    这是我实现控件的方式:

    <sch:pattern>
        <sch:let name="min-origin" value="number(/tests_root/bases/bound/Origin/@value)"/>
        <sch:let name="max-end" value="number(/tests_root/bases/bound/End/@value)"/>
    
        <sch:rule context="test/End | test/Origin">
            <sch:assert test="@value &lt;= $max-end and @value &gt;= $min-origin" ><sch:name/>/@value is not within the allowed range [<sch:value-of select="$min-origin"/>,<sch:value-of select="$max-end"/>]. </sch:assert>
        </sch:rule>
    </sch:pattern>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-30
      • 2020-07-09
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 2019-04-30
      相关资源
      最近更新 更多