如何使用 zero_width_space 进行文字换行

How to use zero_width_space for text wrapping

我发现这段代码将数据包装在一个单元格中,但它没有考虑这个词,即如果完整的词不能放在该行中,它不会改变该行。它在换行之前写了几个字母。

我应该在此代码中修改什么,以便如果特定单词未在该行中得到调整,它会更改该行。

另外,我是 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>

for ex - "I found this piece of code which wraps the data inside a cell "..它在单元格中显示为

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

包装由单元格自动提供。 Zero_width_space 在每个字符后包含一个零宽度 space,因此如果要求不是以字符方式填充单元格,则最好不要调用此模板。