2015-11-16 31 views
0

我发现这段代码,它封装的单元中的数据,但它并没有考虑到这个词即如果完整的话不能安装在线路,它不改变线。它改变线之前写几个字母。如何使用zero_width_space文本包装

我应该在这段代码中修改什么,以便如果特定单词没有在行中进行调整,则会更改该行。

另外,我是xsl -fo的新手。我已经理解了大部分代码,但是如果能解释一点,我们将不胜感激。

<xsl:template name="zero_width_space_1"> 
    <xsl:param name="data"/> 
    <xsl:param name="counter" select="0"/> 
    <xsl:choose> 
     <xsl:when test="$counter &lt; string-length($data)"> 
      <xsl:value-of select='concat(substring($data,$counter,1),"&#8203;")'/> 
      <xsl:call-template name="zero_width_space_2"> 
       <xsl:with-param name="data" select="$data"/> 
       <xsl:with-param name="counter" select="$counter+1"/> 
      </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
     </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

    <xsl:template name="zero_width_space_2"> 
    <xsl:param name="data"/> 
    <xsl:param name="counter"/> 
     <xsl:value-of select='concat(substring($data,$counter,1),"&#8203;")'/> 
     <xsl:call-template name="zero_width_space_1"> 
     <xsl:with-param name="data" select="$data"/> 
     <xsl:with-param name="counter" select="$counter+1"/> 
     </xsl:call-template> 
    </xsl:template> 

    and then placing a call to zero_width_space_1 like following- 

    <xsl:call-template name="zero_width_space_1"> 
     <xsl:with-param name="data" select="span"/> 
    </xsl:call-template> 

为前 - “我发现这个代码段,它封装在细胞内的数据” ..它示出了如在细胞中作为

I found th 
is piece o 
f code whi 
ch wraps t 
he data in 
side a cel 
l 
+0

您能否提供一个无法正常工作的文本示例? –

+0

已编辑我的答案。这个代码应该工作吗? – master

+1

它正在写它的工作。它将在每个角色之间放置一个零宽度空间,以便线条可以在任何两个角色之间断开。如果你没有使用它,线条只会在空格字符处打破。你想要打破哪些文字?如果是在字典中找到的单词,那么您应该考虑在您的FO格式化程序中使用连字支持构建。 –

回答

1

包装被细胞自动提供。 Zero_width_space在每个字符之后都包含一个零宽度空间,所以如果需求不是以字符为单位填充单元格,则最好不要调用此模板。