xsltxsl-fo

XSL-FO Table rows page breaks


I have a simple xsl-fo table that displays a collection of violations. Each violation is a group of 3 rows in the table. Each group can be different height some violation attributes are larger that others.. There could be hundreds of violation groups on the page. I am looking for a solution to page brake the table after last row in the violation group so that 1 violation is not broken into 2 pages. Current code does unfortunately brake the table chaotic.

I am new to XSL-FO and did not try any solutions yet. Below is my FO Table. I hope I made sense. My environment is XLS 1.0

<fo:table table-layout="fixed" width="100%">
  <fo:table-column/>
  <fo:table-column/> 
  <fo:table-column/> 
  
  <fo:table-body>                  
    
     <!--Violation Group 1-->
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 1 Attrib 1</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 1 Attrib 2</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 1 Attrib 3</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 1 Attrib 4</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 1 Attrib 5</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 1 Attrib 6</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 1 Attrib 7</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 1 Attrib 8</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 1 Attrib 9</fo:block></fo:table-cell>
    </fo:table-row>
    
     <!--Violation Group 2 Possible Brake here if group below does not fit on the page-->
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 2 Attrib 1</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 2 Attrib 2</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 2 Attrib 3</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 2 Attrib 4</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 2 Attrib 5</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 2 Attrib 6</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 2 Attrib 7</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 2 Attrib 8</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 2 Attrib 9</fo:block></fo:table-cell>
    </fo:table-row>  
    
    <!--Violation Group 3 Possible Brake here if group below does not fit on the page-->
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 3 Attrib 1</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 3 Attrib 2</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 3 Attrib 3</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 3 Attrib 4</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 3 Attrib 5</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 3 Attrib 6</fo:block></fo:table-cell>
    </fo:table-row>
    <fo:table-row>
      <fo:table-cell><fo:block>Violation 3 Attrib 7</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 3 Attrib 8</fo:block></fo:table-cell>
      <fo:table-cell><fo:block>Violation 3 Attrib 9</fo:block></fo:table-cell>
    </fo:table-row>  

  
  </fo:table-body>
</fo:table>

Solution

  • Add keep-with-next.within-page="always" (or keep-with-next.within-column="always") to the first two fo:table-row in a violation group.