【发布时间】:2014-01-24 19:28:28
【问题描述】:
我希望我的字符串以我使用 XSLT XPATH 从 XML 生成的 pdf 格式显示。我的 XML 包含带有一些空格的字符串,但问题是 xslt 会自动修剪这些字符串。我已经在这个 W3SCHOOL 链接上检查过了 Try it yourself。每当我添加一些额外的空间时,它就会自动被修剪,这在我的情况下我真的不需要。任何帮助将不胜感激。
--------更新------------
我尝试用  替换字符串中的所有空格并尝试显示它,但xslt 没有将  作为空格。它就像字符串的一部分一样考虑它。
我还尝试使用递归将字符串中的特殊字符替换为空格(我已将空格替换为 xml 中的一个字符,现在我的 xml 包含我需要空格的那个字符)但它在递归调用时显示 named template is not available。
<xsl:template
name="add-spaces">
<!-- COMMENTS is string containing ~ where I need spaces -->
<xsl:param
name="text"
select="COMMENTS" />
<xsl:if
test="$text != ''">
<xsl:variable
name="letter"
select="substring($text, 1, 1)" />
<xsl:when
test="$letter = '~'">
<fo:inline>
<xsl:text> </xsl:text>
</fo:inline>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:value-of
select="$letter" />
</fo:inline>
</xsl:otherwise>
<xsl:call-template
name="add-spaces">
<xsl:with-param
name="text"
select="substring-after($text, $letter)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
【问题讨论】:
-
请提供一些您的字符串被修剪的示例代码,并说明您正在使用哪些工具(FOP?)。
-
XSLT 和 XPath 不生成 PDF 文件。那你用什么工具?在任何情况下,您都需要在此处添加您的 XSLT 代码。
标签: xml string xslt xpath trim