XSL-FO在表格单元格内包裹长文本

问题描述 投票:0回答:1

我正在使用XSL-FO作为报告查询模板,将Oracle APEX在运行时生成的表导出为pdf。不幸的是,单元格中的长单词没有被包装,并且它们与相邻单元格重叠,从而使报告确实难看且无用。如何解决呢?注意:我知道这个问题已经被问过很多次了。我的问题是,我发现的所有解决方案似乎都不起作用。特别是,我正在实施在这里找到的内容:XSL-FO: Force Wrap on Table Entries

使用此解决方案,什么都没有发生。我尝试在模板内插入红色文本命令,以检查其是否正常运行,但答案是否定的。您可以看到我也尝试过使用“连字符”和“换行选项”,如对该问题的其他答案所示,但没有成功。我怎样才能解决这个问题? “零空间插入”模板是否放置在正确的位置?

这是我的代码:

 <xsl:stylesheet xmlns:fox="http://xml.apache.org/fop/extensions" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" extension-element-prefixes="saxon" >
    <xsl:variable name="_XDOFOPOS" select="''"/>
    <xsl:variable name="_XDOFOPOS2" select="number(1)"/>
    <xsl:variable name="_XDOFOTOTAL" select="number(1)"/>
    <xsl:variable name="_XDOFOOSTOTAL" select="number(0)"/>

    <!-- VARIOUS OTHER ATTRIBUTES HERE  -->

    <xsl:attribute-set name="cell">
        <xsl:attribute name="background-color">#BODY_BG_COLOR#</xsl:attribute>     
        <xsl:attribute name="color">#BODY_FONT_COLOR#</xsl:attribute>
        <xsl:attribute name="padding-start">5.15pt</xsl:attribute>
        <xsl:attribute name="vertical-align">top</xsl:attribute>
        <xsl:attribute name="padding-top">0.0pt</xsl:attribute>
        <xsl:attribute name="padding-end">5.15pt</xsl:attribute>
        <xsl:attribute name="number-columns-spanned">1</xsl:attribute>
        <xsl:attribute name="height">0.0pt</xsl:attribute>
        <xsl:attribute name="padding-bottom">0.0pt</xsl:attribute>
                <xsl:attribute name="font-style">italic</xsl:attribute>
                <xsl:attribute name="color">blue</xsl:attribute>
        <xsl:attribute name="hyphenate">true</xsl:attribute>
        <xsl:attribute name="wrap-option">wrap</xsl:attribute>
    </xsl:attribute-set>
    <xsl:attribute-set name="header-color">
        <xsl:attribute name="background-color">#HEADER_BG_COLOR#</xsl:attribute>
        <xsl:attribute name="color">#HEADER_FONT_COLOR#</xsl:attribute>
    </xsl:attribute-set>


    <!-- Trying this to wrap long words   -->

    <xsl:template match="text()">    
        <xsl:call-template name="intersperse-with-zero-spaces">
            <xsl:with-param name="str" select="."/>
                <xsl:attribute name="color">red</xsl:attribute>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="intersperse-with-zero-spaces">
        <xsl:param name="str"/>
        <xsl:variable name="spacechars">
            &#x9;&#xA;
            &#x2000;&#x2001;&#x2002;&#x2003;&#x2004;&#x2005;
            &#x2006;&#x2007;&#x2008;&#x2009;&#x200A;&#x200B;
        </xsl:variable>

        <xsl:if test="string-length($str) &gt; 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>&#x200B;</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>  
    <!-- long word wrap end  -->


    <xsl:template match="DOCUMENT"> 
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <!-- OTHER STUFF AND THE TABLE ... -->                      

        </fo:root>
    </xsl:template>

</xsl:stylesheet>
xml oracle-apex word-wrap xsl-fo
1个回答
0
投票

要查看是否使用了模板,请更改:

© www.soinside.com 2019 - 2024. All rights reserved.