继续 多个跨度文本合并为单个跨度 - XSLT

Continue Multiple span text merged in single span - XSLT

如何将多个 span 元素继续合并到单个 span 元素中 S/B。
输入XML

<root>
    <p>Paragraph <span>a</span><span>b</span><span>c</span><span>d</span> Under Continuing <span>Court</span> Jurisdiction</p>
    <p>Paragraph <span>a</span><span>b</span><span>c</span><span>d</span> Under Continuing Court <span>Jurisdiction</span></p>
</root>

预期输出

<root>
    <p>Paragraph <span>abcd</span> Under Continuing <span>Court</span> Jurisdiction</p>
    <p>Paragraph <span>abcd</span> Under Continuing Court <span>Jurisdiction</span></p>
</root>

XSLT 代码

        <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="span">
    <xsl:copy>
        <xsl:apply-templates/>
        <xsl:for-each select="following-sibling::*[1][self::span]">
            <xsl:value-of select="."/>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

p 元素的模板应符合

 <xsl:template match="p">
        <xsl:copy>
            <xsl:for-each-group select="node()" group-adjacent=". instance of element(span)">
                <xsl:choose>
                    <xsl:when test="current-grouping-key()">
                        <span>
                            <xsl:apply-templates select="current-group()/node()"/>
                        </span>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates select="current-group()"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each-group>
        </xsl:copy>
    </xsl:template>