Question

I am creating an xsl fo table that will have a varying number of columns. The application uses Apache FOP to display the transformed document. When there is a low number of columns, everything displays fine (i.e. content of the cells is centered and displayed in full although some columns end up taking up two lines because the text wraps). However, some tables have over 12 columns, and this is where the problem occurs: in the column header cells, the name of the column is all the way to the right of the cell taking multiple lines. It looks like the words are wrapping, but even the last two characters are seemingly cut off. The text is not leaking into the neighboring cells.

Here is the input xml file in this case it's a row for the table header and one row for the body for brevity's sake. I didn't include the chart elements referenced in the xsl document as that part displays properly:

<exports>
   <export>
     <table>
        <tblRow>
            <hdrCell>Month</hdrCell>
            <hdrCell>Allow Amt PEPM Med</hdrCell>
            <hdrCell>Allow Amt PEPM Rx</hdrCell>
            <hdrCell>Allow Amt PEPM Med and Rx</hdrCell>
            <hdrCell>Allow Amt PMPM Med</hdrCell>
            <hdrCell>Allow Amt PMPM Rx</hdrCell>
            <hdrCell>Allow Amt PMPM Med and Rx</hdrCell>
            <hdrCell>Employees Avg Med or Rx</hdrCell>
            <hdrCell>Members Avg Med or Rx</hdrCell>
            <hdrCell>Net Pay PEPM Med</hdrCell>
            <hdrCell>Net Pay PEPM Rx</hdrCell>
            <hdrCell>Net Pay PEPM Med and Rx</hdrCell>
            <hdrCell>Net Pay PMPM Med</hdrCell>
            <hdrCell>Net Pay PMPM Rx</hdrCell>
            <hdrCell>Net Pay PMPM Med and Rx</hdrCell>
        </tblRow>
        <tblRow>
            <tblCell>Jan 2010</tblCell>
            <tblCell>11</tblCell>
            <tblCell>202</tblCell>
            <tblCell>213</tblCell>
            <tblCell>26</tblCell>
            <tblCell>30</tblCell>
            <tblCell>56</tblCell>
            <tblCell>56</tblCell>
            <tblCell>44</tblCell>
            <tblCell>11</tblCell>
            <tblCell>22</tblCell>
            <tblCell>33</tblCell>
            <tblCell>12</tblCell>
            <tblCell>12</tblCell>
            <tblCell>24</tblCell>
            <tblCell>1</tblCell>
        </tblRow>

    </table>
</export>

And here is the xsl file that transforms the input file to xsl fo. I am new to xsl.

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <xsl:output method="xml" indent="yes"/>
   <xsl:template match="/">
   <fo:root>
         <fo:layout-master-set>
             <fo:simple-page-master master-name="exportPage">
                 <fo:region-body />
             </fo:simple-page-master>
         </fo:layout-master-set>
         <fo:page-sequence master-reference="exportPage">
             <fo:flow flow-name="xsl-region-body">
                  <fo:block id="chartBlock">
                          <!-- THIS PART WORKS FINE -->
                  </fo:block>
                 <!-- THE PROBLEM PART -->
                 <fo:block id="tableBlock" margin="0.25in">
                        <xsl:apply-templates select="exports/export/table"/>
                 </fo:block>
             </fo:flow>
        </fo:page-sequence>
    </fo:root>

</xsl:template>
    <!-- Creates the table -->
    <xsl:template match="table">
        <fo:table table-layout="fixed" width="100%" >
            <fo:table-header>
                <fo:table-row>
                    <xsl:apply-templates select="tblRow[position() = 1]"/>
                </fo:table-row>
            </fo:table-header>
            <fo:table-body>
                <xsl:apply-templates select="tblRow[position() > 1]"/>
            </fo:table-body>
        </fo:table>
    </xsl:template>

    <xsl:template match="hdrCell">
        <fo:table-cell background-color="#666" border-right-style="solid" border-right-width="1px" border-right-color="white" empty-cells="show">
            <fo:block color="white" font-family="arial, helvetica, sans-serif" font-size="xx-small"><xsl:value-of select="."/></fo:block>
        </fo:table-cell>
    </xsl:template>

    <xsl:template match="tblCell">
   <fo:table-cell border-bottom-style="solid" border-bottom-width="1px"
   border-bottom-color="#E3E3E3">
   <fo:block color="#7E7E7E" font-family="arial, helvetica, sans-serif" font-                                                size="xx-small"><xsl:value-of select="."/></fo:block>
        </fo:table-cell>
    </xsl:template >

    <xsl:template match="tblRow[position() > 1]">
        <fo:table-row>
            <xsl:apply-templates />
        </fo:table-row>
    </xsl:template>

 </xsl:stylesheet>

I have tried setting a padding right property for each table-cell's block element hoping it would shift the text to the left to no avail. I have tried adjusting the 'width' property of each block element that is a child of a table-cell. I am new to xsl in general, so I'm not sure how to proceed. Would it be helpful to specify elements with a specific width? What can I do to ensure the full width of the table is displayed in the pdf and is without this jumbled, truncated cell content? Also, all units are in 'px' where not specified.

Thanks in advance,

Brandt

Was it helpful?

Solution

Answer: removing the margin="0.25in" from the surrounding block yields the result I think you expect (except of course for the margin on that block). To be clear, change this:

<fo:block id="tableBlock" margin="0.25in">
      <xsl:apply-templates select="exports/export/table"/>
</fo:block>

And remove the margin="0.25in".

Note: This is not the result you would get from a different formatter. I used RenderX on your original file and you get what you expect and the correct result. I used FOP and get the incorrect result but remove that indent (which is obviously being inherited someway improperly to only one dimension of table cells).

One additional note: You have 15 header cells and 16 cells in your sample.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top