如何使用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
相关产品推荐
相关产品推荐

