【发布时间】:2019-04-29 17:57:49
【问题描述】:
我想要一个规则来确保任何div[@class='extend']/div[@class='check'] 位于div[@class='chapter'] 的最后。请注意,可能还有其他具有不同嵌套 div 的“扩展”分区(例如 div[@class='extend']/div[@class='video']),其位置预计不会是最后一个。 div[@class='extend']/div[@class='check'] 的嵌套位使我绊倒我写这条规则。
我试过了:
XML
<test>
<div class="chapter" id="s1">
<h1 class="title">18.3</h1>
<div class="intro" id="s2">
<p>Some intro text here</p>
</div>
<!--Incorrect position of div class="extend"/div class="check"-->
<div class="extend" id="s3">
<div class="check" id="s4">
<div class="metadata" id="s5">
<div class="title" id="s6">
<p>Check 18.3</p>
</div>
</div>
<h1 class="title">Check 18.3</h1>
<p>This is the Check for Chapter 18.3</p>
</div>
</div>
<!---\-\-\-->
<div class="sect1" id="s7">
<h1 class="title">Section text here</h1>
<p>text text text.</p>
<div class="extend" id="s8">
<div class="video">
<div class="metadata" id="s9">
<div class="title" id="s10">
<p>Video 18.3</p>
</div>
</div>
<h1 class="title">Video 18.3</h1>
<p>This is the Video for Chapter 18.3</p>
</div>
</div>
<div class="sect2" id="s11">
<h1 class="title">Section text here</h1>
<p>text text text.</p>
</div>
</div>
<!--div class="extend"/div class="check" should be here as last div of chapter-->
</div>
</test>
Schematron:
<pattern id="lastdiv">
<rule context="xhtml:div[@class='check']">
<assert test="(ancestor::xhtml:div[@class='chapter']/xhtml:div[@class='extend'])[last()]" role="error">This check (with <value-of select="@id"/>) should be the last extend div within a chapter.</assert>
</rule>
</pattern>
但是,这并没有找到我预期的结果(应该会产生错误)。
【问题讨论】:
-
最后一个是什么意思?最后的什么?章节内的任何元素或任何
div[@class = 'extend']?
标签: xml xpath schematron