首页 > 解决方案 > 如果另一个节点的内容与某个值匹配,则用于检查测试节点的 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>

有没有办法让一个节点的测试以不同节点的值为条件?

标签: xmlxslt-2.0schematron

解决方案


你可以写一个规则

<rule context="record[not(type = ('Audio', 'Video'))]">
  <assert test="preview">Needs preview image</assert>
</rule>

推荐阅读