【发布时间】:2011-05-20 01:03:47
【问题描述】:
我在将我的 modspecs 发布为 pdf (XSL-FO) 时遇到了问题。我的表格有问题,其中一个单元格的内容将其列溢出到下一个。如何在文本上强制中断以便创建新行?
我无法手动插入零空格字符,因为表格条目是以编程方式输入的。我正在寻找一个简单的解决方案,我可以简单地添加到 docbook_pdf.xsl(作为 xsl:param 或 xsl:attribute)
编辑: 这是我目前所在的位置:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:import href="urn:docbkx:stylesheet"/>
...(the beginning of my stylesheet for pdf generation, e.g. header and footer content stuff)
<xsl:template match="text()">
<xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="intersperse-with-zero-spaces">
<xsl:param name="str"/>
<xsl:variable name="spacechars">
	

      
     ​
</xsl:variable>
<xsl:if test="string-length($str) > 0">
<xsl:variable name="c1" select="substring($str, 1, 1)"/>
<xsl:variable name="c2" select="substring($str, 2, 1)"/>
<xsl:value-of select="$c1"/>
<xsl:if test="$c2 != '' and
not(contains($spacechars, $c1) or
contains($spacechars, $c2))">
<xsl:text>​</xsl:text>
</xsl:if>
<xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="substring($str, 2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
这样,表格单元格中的长词就成功分解了!不幸的是,副作用是其他地方的普通文本(如在sextion X下)现在会分解单词,以便它们出现在单独的行中。有没有办法将上述过程隔离到表中?
【问题讨论】:
-
这看起来更像是一个 XSL-FO 词汇问题。我已经这样重新标记了。如果您认为是 XSLT 问题,请提供输入示例和所需输出。
-
@Alejandro:是的,它在技术上是一个 XSL-FO 问题(因为该问题不会在 html 中存在)。我想我希望有一种方法可以在 xml 中添加一些东西。
-
您想要一个将零空格字符放入文本的 XSLT 解决方案吗?如果是这样,您能否提供您的 XSL-FO 的最小可能示例以及您需要将哪些文本/位置设为可拆分?