xml - 如果另一个节点的内容与某个值匹配,则用于检查测试节点的 Schematron
问题描述
我有一组记录需要检查以确保节点存在,但前提是记录不是特定类型。例如:
<record>
<type>Audio</type>
</record>
<record>
<type>Video</type>
</record>
<record>
<type>Text</type>
<preview>https://website.com/preview.jpg</preview>
</record>
我想说一个记录如果没有<preview>
字段是无效的,除非它是音频或视频文件,在这种情况下没有<preview>
字段是可以的。
但是这样的事情不起作用:
<pattern>
<rule context="record/type !='Audio' and record/type !='Video'">
<assert test="record/preview">Needs preview image</assert>
</rule>
</pattern>
有没有办法让一个节点的测试以不同节点的值为条件?
解决方案
你可以写一个规则
<rule context="record[not(type = ('Audio', 'Video'))]">
<assert test="preview">Needs preview image</assert>
</rule>
推荐阅读
- swift - Swift:使用应用程序/八位字节流响应的 GET 请求
- ios - 试图让 Chatto Demo 代码在我自己的应用程序中工作并断言失败
- sql - SQL 子查询被附加为字符串而不是正确的查询
- html - 背景图像未显示在烧瓶中
- c - 如何在已经安装了 OpenSSL 的 Linux 中使用 BoringSSL?
- python - 如何仅替换数据框熊猫中最大值的第一个实例?
- laravel - 如何将 UTC 日期时间转换为 BST 时间英国夏令时 (BST) Laravel Carbon
- python - 前 4 个术语发生了什么?
- java - 如何列出字符串中的所有提及
- javascript - 在Javascript中删除数组中的一行