我的问题与:具有重叠元素的 XSLT?– 但建议的解决方案对我不起作用。
输入
我有一些像这样编码的 TEI-XML:
<delSpan spanTo="#abcbb6b8-b7bd-4b96-93c1-0a34500e12c0"/>
<lg>
<l>some text that is deleted</l>
</lg>
<lg>
<l>much more text</l>
<l>another line of text</l>
</lg>
<anchor xml:id="abcbb6b8-b7bd-4b96-93c1-0a34500e12c0"/>
我想用 XSL 处理它,我的输出应该如下所示:
<div class="delSpan">
<div class="lg">
<span>some text that is deleted</span>
</div>
<div class="lg">
<span>much more text</span>
<span>another line of text</span>
</div>
</div>
XSLT 目前我正在尝试使用以下模板:
<xsl:template match="tei:delSpan">
<xsl:variable name="id">
<xsl:value-of select="substring-after(@spanTo, '#')"/>
</xsl:variable>
<xsl:for-each-group select="*" group-ending-with="tei:anchor[@xml:id=$id]">
<div class="delSpan">
<xsl:apply-templates />
</div>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="tei:lg">
<div class="lg">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="tei:l">
<span>
<xsl:apply-templates/>
</span>
</xsl:template>
但这只会产生以下输出:
<div class="lg">
<span>some text that is deleted</span>
</div>
<div class="lg">
<span>much more text</span>
<span>another line of text</span>
</div>
所以我问自己是否有任何常见且简单的解决方案来处理上述所谓的里程碑元素和流程?