稍微简化一下,我的 XML 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<entry>
<form>word</form>
<gram>noun</gram>
<span style="bold">1.</span>
<def>this is a definition in the first sense.</def> – <cit type="example">
<quote>This is a <span style="bold">quote</span> for the first sense. </quote>
</cit>
<span style="bold">2.</span>
<def>This is a definition for the second sense</def> – <cit type="example">
<quote>This is a quote for the second sense.</quote>
</cit>
</entry>
</dict>
我需要使用 XSLT 2.0 或 3.0 对其进行转换以获得以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<entry>
<form>word</form>
<gram>noun</gram>
<sense n="1">
<def>this is a definition in the first sense.</def> – <cit type="example">
<quote>This is a <span style="bold">quote</span> for the first sense. </quote>
</cit>
</sense>
<sense n="2">
<def>This is a definition for the second sense</def> – <cit type="example">
<quote>This is a quote for the second sense.</quote>
</cit>
</sense>
</entry>
</dict>
Тhere 可以有两种以上的感觉,span style bold 可以出现在其他地方,所以我们需要专门识别类似tei:span[@style='bold'][matches(text(), '^\d\.')]
的东西。
我很难将它放在一个样式表中,该样式表还将提取跨度文本节点的数字并将其用作新元素的属性值<sense>
。
我将非常感谢您的tips.x