title: how to keep table with header but allow page breaks inside table body in XSL-FO using FOP
body: <p>I'm generating a PDF using Apache FOP and a XSL-FO stylesheet. In the PDF, I output headings (html equiv h1) which belong to a table, so should be kept together always. However, my tables may also contain so much data that they don't necessarily fit on one page. </p>
  
  <p>The desired result is a rule set that allows a heading to be kept with the table and fit both on one page if possible, but if the table data is so long that it does not fit on one page, then page breaks would be inserted in the table while still keeping the heading element on the same page as the start of the table.</p>
  
  <p>The solution I have right now does keep the heading and the table together, but I get an Content overflows error for the table data if everything does not fit onto one page. I was hoping that page-break-inside: avoid set on the table element would help with this, but apparently not... suggestions?</p>
  
  <p>Example xsl (cut short for readability):</p>
  
  <pre><code>&lt;!-- add test table with header that should stay on same page --&gt;
  &lt;fo:block font-size="20pt" font-weight="bold"&gt;Table header&lt;/fo:block&gt;
  
  &lt;fo:table keep-with-previous.within-page="always"
        page-break-inside="avoid" 
        table-layout="fixed" border-width="1mm" border-style="solid"&gt;
    &lt;fo:table-column column-width="auto" /&gt;
    &lt;fo:table-column column-width="30mm" /&gt;
  
    &lt;fo:table-header text-align="center" background-color="silver"&gt;
      &lt;fo:table-row&gt;
        &lt;fo:table-cell padding="1mm" border-width="1mm" border-style="solid"&gt;
      &lt;fo:block&gt;First name&lt;/fo:block&gt;
        &lt;/fo:table-cell&gt;
        &lt;fo:table-cell padding="1mm" border-width="1mm" border-style="solid"&gt;
      &lt;fo:block&gt;Last name&lt;/fo:block&gt;
        &lt;/fo:table-cell&gt;
      &lt;/fo:table-row&gt;
    &lt;/fo:table-header&gt;
    &lt;fo:table-body&gt;
      &lt;!-- the table-rows can be repeated N times, spanning several pages --&gt;
      &lt;fo:table-row &gt;
        &lt;fo:table-cell padding="1mm" border-width="1mm" border-style="solid"&gt;
      &lt;fo:block&gt;ab&lt;/fo:block&gt;
        &lt;/fo:table-cell&gt;
        &lt;fo:table-cell padding="1mm" border-width="1mm" border-style="solid"&gt;
      &lt;fo:block&gt;cd&lt;/fo:block&gt;
        &lt;/fo:table-cell&gt;
      &lt;/fo:table-row&gt;
      &lt;!-- .... more table-row:s ---&gt; 
  </code></pre>
  
  <h2>Update on desired output</h2>
  
  <p>To better describe what result I'm looking for:</p>
  
  <p>The result document contains both text paragraphs, headings and tables. </p>
  
  <ol>
  <li>If the amount of content is such that the table would have only one or two rows on the next page, then the xsl-fo should move the entire table and the heading to the next page provided that it fits on that page entirely. </li>
  <li>If on the other hand the table as so many rows that it wouldn't fit on an entirely new page anyway, then output should be started right away in the document flow, while still allowing the table to be split acros several pages.</li>
  </ol>
  
  <p>If I remove page-break-inside="avoid", then I get a table that breaks across several pages nicely, but cases described in #1 would not be matched. I.e. it does not move a table and it's heading entirely to the next page if only a few rows would end up being moved to the next page. If I leave page-break-inside, then I get a content overflow problem with long tables, because rows that don't fit on the page are not moved to the next page.</p>
  
  <p>I guess one of the basic problems is that my output tables are very dynamic in length and unfortunately I don't have any control over what amount of data gets produced into the tables.</p>