互斥XPath测试



我正在尝试编写一个Schematron规则来执行以下测试…

如果根下没有li包含"abc"且根中包含title, "def"则报告

我遇到的问题是我得到了很多假阳性。这是我当前的XPath…

<rule context="li">
                <assert test="not(contains(text(),'abc')) and ancestor::root/descendant::title = 'def'">Report this.</assert>
            </rule>

我的输出最终报告了不包含"abc"的每个li,我理解,因为它正在测试每个li并报告。

但是,我不知道如何编写XPath以便测试是否有任何li包含"abc"。

谢谢!

问题是,正如您所暗示的,您在Schematron中将其表示为适用于每个li元素的规则;而您用英语描述的规则则适用于每个root元素。

可以写成

<rule context="root">
  <assert test=".//li[contains(text(),'abc')] or
                not(.//title = 'def')">Report this.</assert>
</rule>

注意,我已经翻转了测试的意义,以符合你的英语描述

如果根下没有li包含"abc"且根中包含title, "def"则报告

由于您使用的是<assert>元素,因此您断言的内容与您想要报告的内容相反。使用<report>元素可能更有意义:

<rule context="root">
  <report test="not(.//li[contains(text(),'abc')]) and
                .//title = 'def'">Report this.</report>
</rule>

最新更新