You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用XSLT在block元素下最后一个group后添加br标签实现分页

修正后XSLT代码

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="group">
        <p>
            <xsl:apply-templates/>
        </p>
        <!-- 判断当前group是否是父节点下的最后一个group元素 -->
        <xsl:if test="count(following-sibling::group) = 0">
            <br/>
        </xsl:if>
    </xsl:template>
    
</xsl:stylesheet>

修正后输出效果

<?xml version="1.0" encoding="UTF-8"?>
<page>
    <stream>
        <block>
            <p>content here</p>
            <p>content here</p>
            <p>content here</p>
            <br/>
        </block>
    </stream>
    <stream>
        <block>
            <p>content here</p>
            <p>content here</p>
            <p>content here</p>
            <br/>
            <!-- please add here br tag -->
        </block>
    </stream>
</page>

如果仅需要给第二个block的最后一个group后加<br>,可以把判断条件调整为test="count(following-sibling::group) = 0 and ancestor::stream[2]"即可。


内容的提问来源于stack exchange,提问作者Kita Ansari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 03:06:03