schematron - Schematron/previous-sibling 和 following-sibling 是同一个元素
问题描述
仅当 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>
解决方案
你拥有大部分作品,但缺少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
孩子,则为真,如果上下文元素是 a ,则不是SUBTASK
。
[position()[1]]
可能是 XPath 1.0 的错误,但在 XPath 2.0 或 XPath 3.0 中,每次都是正确的,因为position()
返回一个非零数字,并且将[1]
单项数字序列减少为第一个(也是唯一一个)数字序列。
推荐阅读
- android - 软键盘隐藏部分editText
- java - 为什么我的 ReceiveMessage.java 类没有将 SMS 正文设置为我的 textview?
- python - 将 DateTime 转换为数字
- azure - 将 Blob 从 BlobStorage 加载到 XslCompiledTransform.Load()
- javascript - 将值从后面的代码传递到 JS
- ios - 在单独的常量文件中验证密码
- web-deployment - BSP 部署 API
- python - Selenoid:为什么我不能运行特定的浏览器版本?
- python - PySpark:DataFrame 到 RDD[DenseVector] 而不是 RDD[Row]
- sql-server - 无法在 SSDT 中预览报表 - 已尝试使用未为此报表服务器注册的数据扩展“oracle”