如何在XSLT转换生成的文本输出中添加页脚
XSLT文本输出添加页脚解决方案
以下是可直接实现你需求的完整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" version="1.0"> <xsl:output method="text"/> <xsl:key name="keyAssessmentID" match="TRU_TRANSFERORDERENTITY" use="ERPORDERLINE"/> <xsl:template match="/"> <!-- 输出页眉 --> <xsl:text>HEADER</xsl:text> <xsl:text>|</xsl:text> <xsl:value-of select="Document/TRU_TRANSFERORDERENTITY[1]/SKU"/> <xsl:text>|</xsl:text> <xsl:value-of select="Document/TRU_TRANSFERORDERENTITY[1]/ERPORDERLINENUM"/> <xsl:text>
</xsl:text> <!-- 输出主体内容 --> <xsl:apply-templates select="Document"/> <!-- 输出页脚 --> <xsl:text>FOOTER</xsl:text> <xsl:text>|</xsl:text> <xsl:value-of select="Document/TRU_TRANSFERORDERENTITY[1]/SKU"/> <xsl:text>|</xsl:text> <xsl:value-of select="Document/TRU_TRANSFERORDERENTITY[1]/ERPORDERLINENUM"/> <xsl:text>
</xsl:text> </xsl:template> <xsl:template match="Document"> <xsl:for-each select=".//TRU_TRANSFERORDERENTITY[generate-id(.) = generate-id(key('keyAssessmentID',ERPORDERLINE)[1])]"> <xsl:variable name="ERPORDERLINE" select="ERPORDERLINE"/> <xsl:value-of select="ERPORDERLINE"/> <xsl:text>|</xsl:text> <xsl:value-of select="WAREHOUSE"/> <xsl:apply-templates select="key('keyAssessmentID', $ERPORDERLINE)"/> </xsl:for-each> </xsl:template> <xsl:template match="TRU_TRANSFERORDERENTITY"> <xsl:text>
</xsl:text> <xsl:value-of select="ERPORDERLINE"/> <xsl:text>|</xsl:text> <xsl:value-of select="ERPORDERLINENUM"/> <xsl:text>|</xsl:text> <xsl:value-of select="SKU"/> </xsl:template> </xsl:stylesheet>
关键调整说明
- 在根模板的主体内容渲染逻辑之后,追加了页脚输出代码,取值规则和页眉保持一致,取第一个
TRU_TRANSFERORDERENTITY节点的SKU和ERPORDERLINENUM字段 - 删除了原代码中多余的
<Document>标签输出(你设置的输出格式为文本,不需要输出XML节点,避免出现多余字符) - 删除了冗余的
TRU_TRANSFERORDERENTITY/*匹配模板,避免输出不必要的标签内容 - 补充了页眉末尾的换行符,避免页眉和第一行主体内容拼接在一起
内容的提问来源于stack exchange,提问作者Tuấn Nguyễn
相关产品推荐
相关产品推荐

