【问题标题】:Schematron for checking for testing a node if the content of another node matches a value如果另一个节点的内容与某个值匹配,则用于检查测试节点的 Schematron
【发布时间】:2019-01-11 23:58:52
【问题描述】:

我需要检查一组记录以确保节点存在,但前提是记录不属于特定类型。例如:

<record>
  <type>Audio</type>
</record>
<record>
  <type>Video</type>
</record>
<record>
  <type>Text</type>
  <preview>https://website.com/preview.jpg</preview>
</record>

我想说,如果记录没有&lt;preview&gt; 字段,则它是无效的,除非它是音频或视频文件,在这种情况下,没有&lt;preview&gt; 字段是可以的。

但是这样的事情是行不通的:

<pattern>
    <rule context="record/type !='Audio' and record/type !='Video'">
        <assert test="record/preview">Needs preview image</assert>
    </rule>
</pattern>

有什么方法可以使一个节点的测试以不同节点的值为条件?

【问题讨论】:

  • &lt;rule context="record[not(type = ('Audio', 'Video'))]"&gt;&lt;assert test="preview"&gt;...&lt;/assert&gt;&lt;/rule&gt;不够吗?

标签: xml xslt-2.0 schematron


【解决方案1】:

你可以写一条规则

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

【讨论】:

  • 非常好——谢谢!如上所述,我收到“无效表达式”错误,但类似这样的工作:'&lt;rule context="record[not(type = 'Audio') and not(type = 'Video')]"&gt;
  • @BHammond,我给出的表达式应该适用于基于 XSLT/XPath 2 及更高版本的 Schematron,因为您将问题标记为 xslt-2.0 我假设了那个版本。但是您已经找到了同样可以完成这项工作的 XSLT/XPath 1 替代方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-13
  • 1970-01-01
相关资源
最近更新 更多