【问题标题】:Schematron / preceding-sibling and following-sibling are the same elementSchematron/previous-sibling 和 following-sibling 是同一个元素
【发布时间】:2021-08-23 19:54:39
【问题描述】:

仅当 EFFECT 元素位于两个 SUBTASK 元素之间时,才拼命让 Schematron 发出警报——它们是彼此的兄弟。非常感谢任何帮助,如果需要更多信息,请告诉我。

下面是一些简单的示例代码:

<TOPIC>
 <SUBTASK></SUBTASK>
 <EFFECT></EFFECT>
 <SUBTASK></SUBTASK>
</TOPIC>

这是我的两次 Schematron 尝试 - 问题在于它会在文档中的每个 EFFECT 上发出警报,而不仅仅是在两个 SUBTASK 之间。 *注意 - EFFECT 是一个通配符,允许在任何地方使用。

<rule context="EFFECT">
 <assert test="preceding-sibling::*[position()[1]][SUBTASK] = following-sibling::*[position()[1]][SUBTASK]" role="error" id="error_EFFECT_between_SUBTASK" 
   >EFFECT not allowed between two SUBTASKs</assert>
</rule>

<rule context="EFFECT">
 <assert test="count(preceding-sibling::*[position()>0]) and preceding-sibling::*[position()[1]][SUBTASK] = following-sibling::*[position()[1]][SUBTASK]" role="error" id="error_EFFECT_between_SUBTASKs" 
  >EFFECT not allowed between two SUBTASK</assert>
</rule>

【问题讨论】:

    标签: schematron


    【解决方案1】:

    你有大部分的碎片,但缺少“自我”轴的self::。尝试(未经测试):

    <rule context="EFFECT">
     <assert test="preceding-sibling::*[1][self::SUBTASK] and
                   following-sibling::*[1][self::SUBTASK]"
             role="error" id="error_EFFECT_between_SUBTASKs" 
      >EFFECT not allowed between two SUBTASK</assert>
    </rule>
    

    如果有SUBTASK 子元素,则[SUBTASK] 为真,如果上下文元素是SUBTASK,则不是。

    [position()[1]] 可能是 XPath 1.0 的错误,但在 XPath 2.0 或 XPath 3.0 中,每次都是正确的,因为 position() 返回一个非零数字,而 [1] 减少了单项数字序列到序列中的第一个(也是唯一一个)数字。

    【讨论】:

    • 非常感谢您看这个!你的查询(尽管仍然提醒所有的影响)让我觉得我需要对这个警报进行更多的微观管理。因为所有 SUBTASK 都位于一个 TOPIC 中,所以这似乎有效。知道我删除了 SELF - 但它“似乎”击中了正确的? 两个SUBTASK之间不允许EFFECT
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    • 2018-06-15
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多