我正在尝试使用有关每一行的新信息来更新HTML文本片段。这是HTML的示例:
<div>
<span class="column1">
<a id="l1"></a>aaaaa<span type="foo">aaa</span>aa
<br id="l2"/>aaaaaaa
</span>
<span class="column2">
<br id="l3"/>aaabbbb
<br id="l4"/>bb<span>123</span>bbbbb
<br id="l5"/>bbbbbbb
<br id="l6"/>ccccccc
</span>
</div>
这是新信息:
<sections>
<section n="1" type="intro" from="1" to="3"/><!-- @from and @to are line numbers -->
<section n="2" type="main" from="3" to="5"/>
<section n="3" type="conclusion" from="6" to="6"/>
</sections>
目标是能够根据此新信息(在此例如划分为多个部分)以不同的方式设置线条样式。因此,最终输出应如下所示:
<div>
<span class="column1">
<a id="l1"/></a><span class="intro">aaaaa<span type="foo">aaa</span>aa</span>
<br id="l2"/><span class="intro">aaaaaaa</span>
</span>
<span class="column2">
<br id="l3"/><span class="intro main">aaabbbb</span>
<br id="l4"/><span class="main">bb<span>123</span>bbbbb</span>
<br id="l5"/><span class="main">bbbbbbb</span>
<br id="l6"/><span class="conclusion">ccccccc</span>
</span>
</div>
这里是我到目前为止拥有的xquery:
for $section in $sections/section
for $line in $s/@from to $s/@to
let $name := $section/@type
let $br := $text//*[contains(@id, concat('l', $line))]
let $newline := <span class="{$name}">{$text//*[contains(@id, concat('l', $line))]/following-sibling::node()[following-sibling::*[contains(@id, concat('l', $line+1))]]}</span>
return
($br, $newline)
显然这不起作用!
<br id="l3"/><span class="intro">...</span>
和<br id="l3"/><span class="main">...</span>
<span>
元素(或其他分组级别,则会丢失。)>我不知道如何获得所需的输出。任何帮助将不胜感激!
我正在尝试使用有关每一行的新信息来更新HTML文本片段。这是HTML的示例:
这里是我尝试将注释中链接的XSLT 3转换为XQuery 3.1: