Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 在字符串长度后强制换行_Xslt_Xsl Fo_Antenna House - Fatal编程技术网

Xslt 在字符串长度后强制换行

Xslt 在字符串长度后强制换行,xslt,xsl-fo,antenna-house,Xslt,Xsl Fo,Antenna House,我想在使用AH Formatter生成的PDF中的字符串长度为14个字符后强制换行。这是我的xsl代码,没有任何断行的尝试: <xsl:attribute-set name="big" use-attribute-sets="bold"> <xsl:attribute name="font-size">38pt</xsl:attribute> <xsl:attribute name="line-height">28.84pt</xsl

我想在使用AH Formatter生成的PDF中的字符串长度为14个字符后强制换行。这是我的xsl代码,没有任何断行的尝试:

<xsl:attribute-set name="big" use-attribute-sets="bold">
  <xsl:attribute name="font-size">38pt</xsl:attribute>
  <xsl:attribute name="line-height">28.84pt</xsl:attribute>
  <xsl:attribute name="text-align">center</xsl:attribute>
  <xsl:attribute name="letter-spacing">1mm</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="small" use-attribute-sets="bold">
  <xsl:attribute name="font-size">27pt</xsl:attribute>
  <xsl:attribute name="line-height">27pt</xsl:attribute>
  <xsl:attribute name="text-align">center</xsl:attribute>
  <xsl:attribute name="letter-spacing">1mm</xsl:attribute>
</xsl:attribute-set>

<xsl:choose>
   <xsl:when test="string-length($count_cover)>=14">
      <fo:block xsl:use-attribute-sets="small">
         <xsl:apply-templates/>
      </fo:block>
    </xsl:when>
    <xsl:otherwise>          
      <fo:block xsl:use-attribute-sets="big">
         <xsl:apply-templates/>
      </fo:block>
   </xsl:otherwise>
</xsl:choose>

38磅
28.84磅
居中
1毫米
27磅
27磅
居中
1毫米

可以用XSL-FO强制换行吗?

在FO中不能强制换行,但可以将字符串拆分为单独的FO块

<xsl:choose>
  <xsl:when test="string-length($count_cover) &gt;= 14">
    <fo:block><xsl:value-of select="substring($count_cover, 1, 13)"/></fo:block>
    <fo:block><xsl:value-of select="substring($count_cover, 14)"/></fo:block>
  </when>
  <xsl:otherwise>
    <fo:block>
      <xsl:value-of select="$count_cover"/>
    </fo:block>
  </xsl:otherwise>
</xsl:choose>

在FO中不能强制换行,但可以将字符串拆分为单独的FO块

<xsl:choose>
  <xsl:when test="string-length($count_cover) &gt;= 14">
    <fo:block><xsl:value-of select="substring($count_cover, 1, 13)"/></fo:block>
    <fo:block><xsl:value-of select="substring($count_cover, 14)"/></fo:block>
  </when>
  <xsl:otherwise>
    <fo:block>
      <xsl:value-of select="$count_cover"/>
    </fo:block>
  </xsl:otherwise>
</xsl:choose>

如果标题可以转换为字符串,则可以插入
作为换行符

<xsl:variable name="cover_title" as="xs:string" select="'Very Long Cover Title! Very Long Cover Title! Very Long Cover Title! '"/>
<xsl:variable name="count_cover" as="xs:integer" select="string-length($cover_title)"/>
<xsl:variable name="lf_position" as="xs:integer" select="14"/>

<xsl:template match="/">
    <xsl:choose>
        <xsl:when test="$count_cover gt $lf_position">
            <fo:block xsl:use-attribute-sets="small">
                <xsl:analyze-string select="$cover_title" regex=".{{1}}">
                    <xsl:matching-substring>
                        <xsl:value-of select="."/>
                        <xsl:if test="position() eq $lf_position">
                            <fo:block/>
                        </xsl:if>
                    </xsl:matching-substring>
                    <xsl:non-matching-substring/>
                </xsl:analyze-string>
            </fo:block>
        </xsl:when>
        <xsl:otherwise>
            <fo:block xsl:use-attribute-sets="big">
                <xsl:value-of select="$cover_title"/>
            </fo:block>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

结果是:

<fo:block font-weight="bold" font-size="27pt" line-height="27pt" text-align="center" letter-spacing="1mm">Very Long Cove<fo:block/>r Title! Very Long Cover Title! Very Long Cover Title! </fo:block>
很长的封面标题!很长的封面标题!很长的封面标题!
但是,此方法忽略单词边界和断字控制。如果您打算制作书的封面标题,最好使用fo:block容器引入AH格式化程序扩展

  • 在封面的固定位置和大小使用fo:block容器作为标题
  • 使用@axf:overflow consolate=“font size”设置属性@overflow=“consolate”。
  • 在fo:block容器中,放置存储标题内容的fo:block
  • 您可以得到期望的结果,因为AH格式化程序会根据内容量自动调整字体大小
  • [示例]

    
    很长的封面标题!很长的封面标题!很长的封面标题!
    
    如果标题可以转换为字符串,则可以插入
    作为换行符

    <xsl:variable name="cover_title" as="xs:string" select="'Very Long Cover Title! Very Long Cover Title! Very Long Cover Title! '"/>
    <xsl:variable name="count_cover" as="xs:integer" select="string-length($cover_title)"/>
    <xsl:variable name="lf_position" as="xs:integer" select="14"/>
    
    <xsl:template match="/">
        <xsl:choose>
            <xsl:when test="$count_cover gt $lf_position">
                <fo:block xsl:use-attribute-sets="small">
                    <xsl:analyze-string select="$cover_title" regex=".{{1}}">
                        <xsl:matching-substring>
                            <xsl:value-of select="."/>
                            <xsl:if test="position() eq $lf_position">
                                <fo:block/>
                            </xsl:if>
                        </xsl:matching-substring>
                        <xsl:non-matching-substring/>
                    </xsl:analyze-string>
                </fo:block>
            </xsl:when>
            <xsl:otherwise>
                <fo:block xsl:use-attribute-sets="big">
                    <xsl:value-of select="$cover_title"/>
                </fo:block>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    
    
    结果是:

    <fo:block font-weight="bold" font-size="27pt" line-height="27pt" text-align="center" letter-spacing="1mm">Very Long Cove<fo:block/>r Title! Very Long Cover Title! Very Long Cover Title! </fo:block>
    
    很长的封面标题!很长的封面标题!很长的封面标题!
    
    但是,此方法忽略了单词边界和断字控制。如果您打算制作书籍封面标题,最好使用fo:block容器引入AH格式化程序扩展

  • 在封面的固定位置和大小使用fo:block容器作为标题
  • 使用@axf:overflow consolate=“font size”设置属性@overflow=“consolate”。
  • 在fo:block容器中,放置存储标题内容的fo:block
  • 您可以得到期望的结果,因为AH格式化程序会根据内容量自动调整字体大小
  • [示例]

    
    很长的封面标题!很长的封面标题!很长的封面标题!
    
  • 如果您试图打断单词(而不是,例如,部件号),则启用连字符可能会比在固定字符数后打断更好

  • 您可以使用
    linefeed treatment=“preserve”
    并插入
    
    而不是
    fo:block
    ,作为对注释的回答。您可以使用

  • 您可以插入一个零宽度的空格,
    ,在每14个字符之后,让AH格式化程序在零宽度空间中断:

    
    

    内部的
    replace()
    在每14个非空格字符后插入字符,外部的
    replace()
    在第15个字符是空格字符时修复该字符

    如果您使用的是比例宽度字体,则某些14个字符的序列(不包括,例如,14个恒定宽度的行号)将比其他字符的宽度大或小,因此您可能需要插入
    在多个字符之间切换,以便AH格式化程序可以在中断前尽最大努力填充行

  • 您可以使用
    axf:word break=“break all”
    在单词内部启用换行。看
  • 如果您试图打断单词(而不是,例如,部件号),则启用连字符可能会比在固定字符数后打断更好

  • 您可以使用
    linefeed treatment=“preserve”
    并插入
    
    而不是
    fo:block
    ,作为对注释的回答。您可以使用

  • 您可以插入一个零宽度的空格,
    ,在每14个字符之后,让AH格式化程序在零宽度空间中断:

    
    

    内部的
    replace()
    在每14个非空格字符后插入字符,外部的
    replace()
    在第15个字符是空格字符时修复该字符

    如果您使用的是比例宽度字体,则某些14个字符的序列(不包括,例如,14个恒定宽度的行号)将比其他字符的宽度大或小,因此您可能需要插入
    在多个字符之间切换,以便AH格式化程序可以在中断前尽最大努力填充行

  • 您可以使用
    axf:word break=“break all”
    在单词内部启用换行。看