我的XSLT没有显示中间的断裂。
输入:此数据是从SQL Server列
获取的 hello
www.xyz.com
hello
line 1
模板:
<xsl:template name="replace">
<xsl:param name="TFooter" />
<xsl:param name="search-string" select="'
'" />
<xsl:if test="contains($TFooter, $search-string)">
<xsl:value-of select="substring-before($TFooter, $search-string)" />
<fo:block />
</xsl:if>
<xsl:if test="contains($TFooter, $search-string)">
<!-- recursive call -->
<xsl:call-template name="replace">
<xsl:with-param name="TFooter" select="substring-after($TFooter, $search-string)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
我们可以从这里调用模板:
<fo:table-row>
<fo:table-cell padding-bottom="1mm" padding-left="0.5cm">
<fo:block disable-output-escaping="yes" font-size="10pt" text-align="left">
<xsl:call-template name="replace">
<xsl:with-param name="TFooter" select="FooterText" />
</xsl:call-template>
</fo:block>
</fo:table-cell>
</fo:table-row>
当前输出:
hello
www.xyz.com
hello
line 1
所需的输出:
hello
www.xyz.com
hello
line 1
如何使用XSLT 1.0实现中间线路断裂?
我认为模板中缺少 <xsl:text>
</xsl:text>
replace
如果您的 INPUT (从SQL Server列获取的数据)在XML中如下:(示例)
<?xml version="1.0" encoding="UTF-8"?>
<FooterText>
hello
www.xyz.com
hello
line 1
</FooterText>
然后可以将代码重写如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<fo:table-row>
<fo:table-cell padding-bottom="1mm" padding-left="0.5cm">
<fo:block disable-output-escaping="yes" font-size="10pt"
text-align="left">
<xsl:call-template name="replace">
<xsl:with-param name="TFooter" select="FooterText" />
</xsl:call-template>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="TFooter" />
<xsl:param name="search-string" select="'
'" />
<xsl:if test="contains($TFooter, $search-string)">
<xsl:value-of select="substring-before($TFooter, $search-string)" />
<xsl:text>
</xsl:text>
<fo:block />
</xsl:if>
<xsl:if test="contains($TFooter, $search-string)">
<!-- recursive call -->
<xsl:call-template name="replace">
<xsl:with-param name="TFooter"
select="substring-after($TFooter, $search-string)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
https://xsltfiddle.liberty-development.net/bfn1y8x/9