7

I have a table in FOP and it is working nicely until I get a very long word. The word then overwrites the cell ending in the table. I tried the wrap-option="wrap" within the table-cell and/or the block of the cell but it doesn't work

**Total Edit**

since I guess it is to complicated to just show bits here is the complete xsl file:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes" />
<xsl:param name="tableCell" select="'1.0'" />

<!-- Globale Variablen START -->

<xsl:param name="tabbgcolor" select="'#EEEEEE'" />



<!-- Globale Variablen ENDE -->

<xsl:template match="/datasheet">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fn="http://www.w3.org/2005/xpath-functions">
        <fo:layout-master-set>
            <fo:simple-page-master page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="1cm" margin-left="1.5cm" margin-right="1.5cm" master-name="first">
                <fo:region-body margin-top="20mm" margin-bottom="20mm" />
                <fo:region-before extent="15mm" />
                <fo:region-after extent="15mcm" />
            </fo:simple-page-master>
            <fo:simple-page-master master-name="new" margin-right="1.0cm" margin-left="1.0cm" margin-bottom="1cm" margin-top="1cm" page-height="21cm" page-width="29.7cm">
                <fo:region-body margin-top="30mm" margin-bottom="20mm" />
                <fo:region-before extent="30mm" />
                <fo:region-after extent="15mm" />
            </fo:simple-page-master>
        </fo:layout-master-set>



        <fo:page-sequence language="de" country="DE" master-reference="new" initial-page-number="1">

            <fo:static-content flow-name="xsl-region-before">
                <fo:block text-align="center" font-size="12pt" padding="5pt" font-weight="bold">
                    <xsl:value-of select="title" />
                </fo:block>
                <fo:block text-align="right" font-size="12pt" padding="5pt" font-weight="bold">
                    <xsl:value-of select="date" />
                </fo:block>
                <fo:block text-align="right" font-size="12pt" padding="0pt" font-weight="bold">
                    <xsl:value-of select="time" />
                </fo:block>
                <fo:block>
                    <fo:leader leader-length="100%" leader-pattern="rule" rule-thickness="2pt" color="black" />
                </fo:block>
            </fo:static-content>

            <fo:static-content flow-name="xsl-region-after">
                <fo:block text-align="center">
                    Seite
                    <fo:page-number />
                    von
                    <fo:page-number-citation ref-id="TheVeryLastPage" />
                </fo:block>
            </fo:static-content>





            <fo:flow flow-name="xsl-region-body">



                <fo:block>
                    <fo:leader />
                </fo:block>
                <fo:block>
                    <fo:leader />
                </fo:block>
                <fo:block>
                    <fo:leader />
                </fo:block>


                <fo:block font-weight="bold" padding="5pt" padding-top="25pt">
                    Jahre <xsl:value-of select="fromYear" /> bis <xsl:value-of select="toYear" />
                </fo:block>

                <fo:block text-align="center">
                    <xsl:choose>
                        <xsl:when test="dataList != ''">
                            <fo:table table-layout="fixed" width="100%" border-style="solide" border-width="1pt">
                                <fo:table-column column-width="25%" border-style="solid" border-width="1pt" />
                                <fo:table-column column-width="25%" border-style="solid" border-width="1pt" />
                                <fo:table-column column-width="25%" border-style="solid" border-width="1pt" />
                                <fo:table-column column-width="25%" border-style="solid" border-width="1pt" />



                                <fo:table-header>
                                    <fo:table-row>
                                        <fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
                                            <fo:block>
                                                Cell1
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
                                            <fo:block>
                                                Cell2
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
                                            <fo:block>
                                                Cell3
                                            </fo:block>
                                        </fo:table-cell>
                                        <fo:table-cell border-style="solid" font-weight="bold" border-width="0pt">
                                            <fo:block>
                                                Cell4
                                            </fo:block>
                                        </fo:table-cell>

                                    </fo:table-row>
                                </fo:table-header>

                                <fo:table-body>
                                    <xsl:for-each select="dataList"> 
                                        <fo:table-row>
                                            <fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
                                                <fo:block text-align="left">
                                                    <xsl:value-of select="data1" />
                                                </fo:block>
                                            </fo:table-cell>
                                            <fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
                                                <fo:block text-align="left">
                                                    <xsl:value-of select="data2" />
                                                </fo:block>
                                            </fo:table-cell>
                                            <fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
                                                <fo:block text-align="left">
                                                    <xsl:value-of select="data3" />
                                                </fo:block>
                                            </fo:table-cell>
                                            <fo:table-cell padding="5pt" border-style="solid" border-width="1pt">
                                                <fo:block text-align="left">
                                                    <xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="data4"/>
</xsl:call-template>
                                                </fo:block>
                                            </fo:table-cell>

                                        </fo:table-row>
                                    </xsl:for-each>  
                                </fo:table-body>

                            </fo:table>
                        </xsl:when>
                        <xsl:otherwise>
                            <fo:block padding="6cm" text-align="center" font-weight="bold" font-size="16pt">No data.
                            </fo:block>
                        </xsl:otherwise>
                    </xsl:choose>
                </fo:block>


                <fo:block id="TheVeryLastPage">
                </fo:block>
            </fo:flow>
        </fo:page-sequence>

        <!-- ___________________________________________________________________________________________________________ -->





    </fo:root>

</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> 




</xsl:stylesheet>

The cell data4 is the one with the problems.... like 255 digits or characters at once with no hyphen oder space.

The input is from a database but could be like:

 <datasheet>
   <dataList>
     <data1>intro</data1>
     <data2>section</data2>
     <data3>cutters</data3>
     <data4>743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348743576746876357467569384657654687465874638563465873487435767468763574675693846576546874658746385634658734874357674687635746756938465765468746587463856346587348</data4>

   </dataList>
 </datasheet>

the result should be a table like:

|cell1  |cell2  |cell3  |cell4  |
_________________________________
|intro  |section|cutters|7435767|
                        |4687635|
                        |7467569|
                        |3846576|
_________________________________

and so on in cell 4

Now the above works

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
Thevagabond
  • 323
  • 2
  • 6
  • 28
  • In order to help with your template that tries to intersperse zero-spaces, please show the `` start tag (the beginning) of the template you already put in, and also the template named "intersperse-with-zero-spaces". Then it would be good to show sample input (at least one chunk with a long string), expect output (the FO), and actual output. – LarsH Jun 26 '13 at 12:39
  • 1
    Thanks for posting the sample data and more of the stylesheet. There must be copy/paste errors in the stylesheet... there is an ``, which is only supposed to occur at the beginning of a template, in the middle of the template. The stylesheet is therefore invalid. Are there supposed to be two templates? Also, I don't yet see the template named intersperse-with-zero-spaces; but maybe you're still adding it. Finally, what XSLT processor are you using - Xalan? XSLT 1.1 was an abandoned version. – LarsH Jun 26 '13 at 13:11
  • the xsl param was C&P error removed that I use the newes FOP bin – Thevagabond Jun 26 '13 at 13:20
  • **THAT'S IT** you got the solution ... needed to be added above the line the upper param needed to be deleted and the first template needed to be closed ... now it works (fixed it see above) – Thevagabond Jun 26 '13 at 13:35
  • Good. I'm surprised your XSLT processor wasn't giving you an error. I'll put the "solution" part of my comment into my answer, so you can accept it (click the check mark). :-) – LarsH Jun 26 '13 at 14:45

3 Answers3

3
<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> 

calling place use to call like below:

<fo:block text-align="left">
   <xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="data4"/>
</xsl:call-template>
  </fo:block>

I tested, it's working fine.

Nicomedes E.
  • 1,326
  • 5
  • 16
  • 26
2

One option would be for you to break up the long number/word in XSLT while you're transforming to FO. You'd have to decide where you want it to break.

See also: XSL-FO fop. Long text flows into adjacent cells/block, obscuring stuff there

Update (copied from comment):

There must be copy/paste errors in the stylesheet... there is an <xsl:param>, which is only supposed to occur at the beginning of a template, in the middle of the template. The stylesheet is therefore invalid. Are there supposed to be two templates? Also, I don't yet see the template named intersperse-with-zero-spaces; but maybe you're still adding it.

Update 2:

The above has been fixed in the Question.

I had assumed the second template couldn't be intersperse-with-zero-spaces, since it was calling that template. It didn't occur to me that it was supposed to be a recursive template!

By the way, if you have the option of using XSLT 2.0, the intersperse-with-zero-spaces template could be replaced by a much more efficient regexp replace.

Community
  • 1
  • 1
LarsH
  • 25,732
  • 8
  • 77
  • 136
  • I tried this but it doesn't work for me. I am triying right now the zero width space approch but not very lucky.. see my edit above – Thevagabond Jun 26 '13 at 11:31
  • The previous comment refers to the part of the answer above the first Update. – LarsH Jun 28 '13 at 03:04
-1

Add hyphenate="true", then it will automatically adjust the spaces in the table cell.

<fo:table-cell border-bottom-width="0px" border-left-width="0px" 
    border-right-width="0px" border-top-width="0px" font-size="9px" 
    padding-left="0px" border-style="solid" border-width="1pt" 
    border-color="white" padding-start="0px" padding-end="2px" 
    padding-before="0px" padding-after="0px" width="16%" display-align="center"
    text-align="start" hyphenate="true">
Nathan Tuggy
  • 2,239
  • 27
  • 28
  • 36
  • Hyphenation has nothing to do with "adjusting spaces", and it does not usually apply to a long numerical string as the one causing the problem. – lfurini Apr 18 '15 at 08:32