0

我有一个包含 xml、pdf 和 tif 文件列表的 XML 文档。我需要通过 Schematron 测试每个 xml 都有一个匹配的 pdf 文件,反之亦然。

我的 XML:

<folder>
    <files>
        <file>foo.xml</file>
        <file>foo.pdf</file>
        <file>bar.xml</file>
        <!-- Missing file <file>bar.pdf</file> -->
        <file>foo.tif</file>
    </files>
</folder>

我的 Schematron:

<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">

<!-- XML/PDF Matches -->

<pattern abstract="false" id="xmlPdfPair">
    <rule context="folder/files//file">
        <assert test="substring-before(.,'.xml') eq substring-before(.,'.pdf')">The XML or PDF (<value-of select="."/>) does not have a matching PDF or XML file.</assert>
    </rule>
</pattern>

我希望规则在文件中应该存在的丢失的 bar.pdf 上触发。我的 Schematron 没有做到这一点。我觉得我在这里需要一个 for-each 构造。使用密钥会使这更简单吗?

4

1 回答 1

1

将其更改为提到以获得所需的验证:

  <pattern abstract="false" id="xmlPdfPair">
    <rule context="//file[contains(text(),'.xml')]">
      <let name="fileName" value="substring-before(.,'.xml')"/>
      <assert test="(following-sibling::file)[1][text()=concat($fileName,'.pdf')]">The XML or PDF
          (<value-of select="."/>) does not have a matching PDF or XML file.</assert>
    </rule>
  </pattern>
于 2014-08-01T06:25:12.710 回答