【问题标题】:Testing for matching file names in Schematron在 Schematron 中测试匹配的文件名
【发布时间】:2014-06-26 21:19:16
【问题描述】:

我有一个包含 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 构造。使用键会使这更简单吗?

【问题讨论】:

    标签: xml xpath-2.0 schematron


    【解决方案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>
    

    【讨论】:

    • 谢谢。我将断言测试更改为 ="(//file)[text()=concat($fileName,'.pdf')]" 因为文件可以按任何顺序列出,不一定是以下兄弟。
    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多