gpt4 book ai didi

schematron - 实现 schematron 规则

转载 作者:行者123 更新时间:2023-12-03 17:23:57 25 4
gpt4 key购买 nike

我是 schematron 的新手,遇到以下问题。这是来自 xhtml 文件的片段:

<div class="provision">
<!-- provision (SECTION) -->
<header>
<!-- headers -->
<div class="desig">
<!-- if provision then header/div@class=desig/span@class=num required -->
<span class="num">1.</span>
</div>
<h1 class="title">prov-title</h1>
</header>
<p class="prov">para-prov-level</p>
<p class="prov">para-prov-level</p>
<div class="glossary">
<!-- glossary -->
<!-- glossary requires dl -->
<dl>
<!-- dl should have dt, and at least one dd -->
<dt> term </dt>
<dd>definition</dd>
<dt> term </dt>
<dd>definition</dd>
</dl>
</div>
<div class="level-1-grp">
<!-- SUBSECTION -->
<header>
<div class="desig">
<span class="num">(1)</span>
</div>
</header>
<p class="level-1">para-level-1</p>
<div class="level-2-grp">
<header>
<div class="desig">
<span class="num">(a)</span>
</div>
</header>
<p class="level-2">para-level-2</p>
</div>
<div class="level-2-grp">
<header>
<div class="desig">
<span class="num">(b)</span>
</div>
</header>
<p class="level-2">para-level-2</p>
</div>
<p class="level-1">para-level-1</p>
</div>
<p class="prov">para-prov-level</p>
</div>

我想创建一个规则来检查如果有 provision 则需要 header/div@class=desig/span@class=num 并且 glossary 需要 dl。我一直在这样尝试,但它不起作用:

<iso:pattern id="structure-provision">
<iso:title>Testing for Provision structure...</iso:title>
<iso:rule context="*:div[@class='provision']">
<iso:assert test="self::*:header/div[@class ='desig']/*:span[@class='num']">if provision then header/div@class=desig/span@class=num required</iso:assert>
</iso:rule>
</iso:pattern>

<!--glossory structure -->

<iso:pattern id="structure-glossory">
<iso:title>Testing for Provision structure...</iso:title>
<iso:rule context="*:div[@class='glossory']">
<iso:assert test="self::*:dl">glossary requires dl</iso:assert>
<iso:assert test="self::*:dl/dt">dl should have a dt</iso:assert>
</iso:rule>

</iso:pattern>

如有任何帮助,我们将不胜感激。谢谢

最佳答案

您在第一个 iso:assert 中缺少 div 元素上的命名空间。

英语不是很准确,所以我用两种方式解释了你的要求。

1) 如果有规定则(header/div@class=desig/span@class=num required AND glossary requires dl)。 “如果 X,则 A 和 B”。如果是这种情况,则应仅使用单一模式。

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<sch:pattern id="structure-provision">
<sch:title>Provisioning structure</sch:title>
<sch:rule context="*:div[@class='provision']">
<sch:assert test="*:header/*:div[@class ='desig']/*:span[@class='num']">
The provision structure requires header/div@class=desig/span@class=num
</sch:assert>
<sch:assert test="*:div[@class='glossary']/*:dl">
Glossary requires dl
</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>

2)(如果有规定则需要 header/div@class=desig/span@class=num)和(词汇表需要 dl)。 “如果 X,则 A。此外,如果 Y,则 B。”如果是这种情况,则应使用两种模式。

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<sch:pattern id="provision-structure">
<sch:title>Provisioning structure</sch:title>
<sch:rule context="*:div[@class='provision']">
<sch:assert test="*:header/*:div[@class ='desig']/*:span[@class='num']">
The provision structure requires header/div@class=desig/span@class=num
</sch:assert>
</sch:rule>
</sch:pattern>

<sch:pattern id="glossary-structure">
<sch:title>Provisioning structure</sch:title>
<sch:rule context="*:div[@class='glossary']">
<sch:assert test="*:dl">
Glossary requires dl
</sch:assert>
<sch:assert test="*:dl/*:dt">
dl requires dt
</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>

我建议将您的要求拆分为多个规则/模式,以使事情更加稳健和有条理。例如,将与供应结构相关的所有规则都放在一个模式中。如果无论词汇表是否在供应结构内都应强制执行词汇表规则,那么词汇表应该有自己的模式。

另外,我会为元素定义和使用命名空间,并在 schematron 规则中使用它。我假设它是 xhtml 或类似的? xpath 表达式将变成类似这样的内容:

<sch:rule context="xhtml:div[@class='provision']">
<sch:assert test="xhtml:header/xhtml:div[@class ='desig']/xhtml:span[@class='num']">
Rule text here
</sch:assert>
</sch:rule>

关于schematron - 实现 schematron 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17593627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com