我的 xslt 没有显示段落中的换行符
My xslt is not showing the line breaks within a paragarph
我的 xslt 没有显示中间换行符。
输入:
此数据取自 sql 服务器列
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
如果您的输入(从sql服务器列中获取的数据)在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>
我的 xslt 没有显示中间换行符。
输入: 此数据取自 sql 服务器列
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
如果您的输入(从sql服务器列中获取的数据)在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>