I'm having an issue where when I publish my modspecs to pdf (XSL-FO). My tables are having issues, where the content of a cell will overflow its column into the next one. How do I force a break on the text so that a new line is created instead?
I can't manually insert zero-space characters since the table entries are programmatically entered. I'm looking for a simple solution that I can just simply add to docbook_pdf.xsl (either as a xsl:param or xsl:attribute)
EDIT: Here is where I'm at currently:
<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 开发者_StackOverflowselect="$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>
With this, the long words are successfully broken up in the table cells! Unfortunately, the side effect is that normal text elsewhere (like in a under sextion X) now breaks up words so that they appear on seperate lines. Is there a way to isolate the above process to just tables?
In the long words, try inserting a zero-width space character between the characters where a break is allowed.
You can use XSLT to insert a zero-width space between every character. Here is one way to do it: http://groups.yahoo.com/neo/groups/XSL-FO/conversations/topics/1177.
Here is a mailing list thread where various approaches to the problem are discussed: http://www.stylusstudio.com/xsllist/200201/post80920.html.
The SourceForge DocBook stylesheets includes a template for breaking up long URLs in FO output; see http://www.sagehill.net/docbookxsl/Ulinks.html#BreakLongUrls. The template (
hyphenate-url
) is in xref.xsl.
Since you're using XSLT 2.0:
<xsl:template match="text()">
<xsl:value-of
select="replace(replace(., '(\P{Zs})(\P{Zs})', '$1​$2'),
'([^\p{Zs}​])([^\p{Zs}​])',
'$1​$2')" />
</xsl:template>
This is using category escapes (http://www.w3.org/TR/xmlschema-2/#nt-catEsc) rather than an explicit list of characters to match, but you could do it that way instead. It needs two replace()
because the inner replace()
can only insert the character between every second character. The outer replace()
matches on characters that are not either space characters or the character added by the inner replace()
.
Inserting after every thirteenth non-space character:
<xsl:template match="text()">
<xsl:value-of
select="replace(replace(., '(\P{Zs}{13})', '$1​'),
'​(\p{Zs})',
'$1')" />
</xsl:template>
The inner replace()
inserts the character after every 13 non-space characters, and the outer replace()
fixes it if the 14th character was a space character.
If you are using AH Formatter, then you can use axf:word-break="break-all"
to allow AH Formatter to break anywhere within a word. See https://www.antenna.co.jp/AHF/help/en/ahf-ext.html#axf.word-break.
精彩评论