通过XSLT在两个自闭合标签之间选择文本

问题描述 投票:1回答:3

我正在尝试选择与某些自闭标记元素相邻的文本。这是到目前为止我得到的。

来源:

<markers>
    <self_closing_marker id="1"/> Some content, possible <othernodes>nodes with text</othernodes>
    <self_closing_marker id="2-3"/> Some more content
</markers>

XSLT:

<xsl:template name="markers" match="self_closing_marker">
    <xsl:value-of select="following-sibling::text()" />
</xsl:template>

问题在于,以下同级将选择所有内容,直到当前包装器的末尾。我发现有一些解决方案使用当前同级变量作为变量,并基于此使用先前同级变量,但是每当实现它们时,我都会得到空标签。

最终目标是获得与]类似的东西>

<markers>
    <marker id="1">Some content, possible nodes with text</marker>
    <marker id="2-3">Some more content</marker>
</markers>

我正在尝试选择与某些自闭标记元素相邻的文本。这是到目前为止我得到的。来源:

xml xslt saxon
3个回答
1
投票

一种方法是用end轴上的第一个self_closing_marker元素分配变量following-sibling::


1
投票

您可以从相反的方向看:


0
投票

如果您准备使用Saxon扩展功能(需要PE或更高版本,则可以使用:

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.