1

我正在尝试根据由其 ID 标识的文档中不同元素中的标准来验证子元素的存在。使用 ISO Schematron 和 XPath 2.0。

举个例子:

<value id="red" bits="16" />

<foo value_id="red">
    <increased_sensitivity/>
</foo>

只有当@id 为“red”的“value”元素在文档中的某处包含属性 bits="16" 时,才应允许元素“increased_sensitive”。

老实说,我什至不确定 Schematron 是否可行,我对它的经验非常有限。

4

1 回答 1

0

假设您想找到 ID 与 foo id 值(在本例中为“red”)匹配的 value 元素,然后检查那里的 bits 值,那么这个 Schematron 模式显示了一种可以完成的方法:


<?xml version="1.0"?>    
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron">

  <sch:let name="root" value="/"/>

  <sch:pattern>
    <sch:rule context="increased_sensitivity">
      <sch:let name="id" value="parent::*/@value_id"/>
      <sch:let name="assoc-bits-value" value="$root//value[@id=$id]/@bits"/>
      <sch:assert test="$assoc-bits-value = 16">When the increased_sensitivity element is used, a
        corresponding value element must exist in the doucment with a bits value of
        "16".</sch:assert>
    </sch:rule>
  </sch:pattern>

</sch:schema>

于 2011-05-31T20:08:54.023 回答