title: Orphans and widows in fo:table to control page break within fo:table-cell
body: <p>I'm faced with a styling problem when using tables with a lot of text within the cells. Sometimes the text is unfortunately separated by the page break. As you can see in the following picture the <strong>paragraph1</strong> from <strong>row3</strong> is divided by the page break.</p>
  
  <p><img src="https://i.stack.imgur.com/VVpTb.jpg" alt="Unfortunate page-break within the cells of **row3**"></p>
  
  <p>What we need is that <strong>row3 paragraph1 line1</strong> is put to the next page together with the rest of the paragraph.</p>
  
  <p>We tried using attributes like "orphans" and "widows" but those do not seem to have any effect within table cells. We also tried using block with <strong>keep-together</strong> attribute, but paragraphs might be larger than one page so that content gets cut off. The only other thing, we could come up with, is to use <strong>keep-with-next</strong> with fo:blocks which we use on the first few paragraphs of a row. But this looks sloppy, complicated and more like a rule of thumb estimate.</p>
  
  <p>I have put together a "minimal" example that can be tested using <a href="http://www.utilities-online.info/foprender/" rel="nofollow noreferrer">http://www.utilities-online.info/foprender/</a> . I hope you can help me with a solution. Maybe you could also tell me why "orphans" and "widows" does not seem to work here.</p>
  
  <p>Thank you in advance!</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
      &lt;item&gt;
          &lt;heading&gt;head1&lt;/heading&gt;
          &lt;description&gt;
              &lt;p&gt;row1 paragraph1 line1
              row1 paragraph1 line2
              row1 paragraph1 line3
              row1 paragraph1 line4
              row1 paragraph1 line5&lt;/p&gt;
  
              &lt;p&gt;row1 paragraph2 line1
              row1 paragraph2 line2
              row1 paragraph2 line3
              row1 paragraph2 line4&lt;/p&gt;
          &lt;/description&gt;
      &lt;/item&gt;
      &lt;item&gt;
          &lt;heading&gt;head1&lt;/heading&gt;
          &lt;description&gt;
              &lt;p&gt;row2 paragraph1 line1
              row2 paragraph1 line2
              row2 paragraph1 line3
              row2 paragraph1 line4
              row2 paragraph1 line5&lt;/p&gt;
  
              &lt;p&gt;row2 paragraph2 line1
              row2 paragraph2 line2
              row2 paragraph2 line3
              row2 paragraph2 line4
              row2 paragraph2 line5
              row2 paragraph2 line6
              row2 paragraph2 line7&lt;/p&gt;
          &lt;/description&gt;
      &lt;/item&gt;
      &lt;item&gt;
          &lt;heading&gt;head1&lt;/heading&gt;
          &lt;description&gt;
              &lt;p&gt;row3 paragraph1 line1
              row3 paragraph1 line2
              row3 paragraph1 line3
              row3 paragraph1 line4
              row3 paragraph1 line5&lt;/p&gt;
  
              &lt;p&gt;row3 paragraph2 line1
              row3 paragraph2 line2
              row3 paragraph2 line3
              row3 paragraph2 line4&lt;/p&gt;
          &lt;/description&gt;
      &lt;/item&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>XSL</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0"&gt;
      &lt;xsl:output encoding="UTF-8" indent="yes" method="xml" standalone="no" omit-xml-declaration="no"/&gt;
  
      &lt;xsl:template match="//root"&gt;
          &lt;fo:root language="DE"&gt;
              &lt;fo:layout-master-set&gt;
                  &lt;fo:simple-page-master master-name="A4-landscape" page-height="21cm" page-width="29.7cm" margin-top="5mm" margin-bottom="5mm" margin-left="5mm" margin-right="5mm"&gt;
                      &lt;fo:region-body margin-top="25mm" margin-bottom="20mm"/&gt;
                      &lt;fo:region-before region-name="xsl-region-before" extent="25mm" display-align="before" precedence="true"/&gt;
                  &lt;/fo:simple-page-master&gt;
              &lt;/fo:layout-master-set&gt;
              &lt;fo:page-sequence master-reference="A4-landscape"&gt;
                  &lt;fo:flow reference-orientation="0" border-collapse="collapse" flow-name="xsl-region-body"&gt;
                      &lt;fo:table&gt;
                          &lt;fo:table-column column-width="80%"/&gt;
                          &lt;fo:table-body&gt;
                              &lt;xsl:apply-templates select="item"/&gt;
                          &lt;/fo:table-body&gt;
                      &lt;/fo:table&gt;
                  &lt;/fo:flow&gt;
              &lt;/fo:page-sequence&gt;
          &lt;/fo:root&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="item"&gt;
          &lt;fo:table-row&gt;
              &lt;fo:table-cell border="solid"&gt;
                  &lt;fo:block&gt;
                      &lt;xsl:value-of select="heading"/&gt;
                  &lt;/fo:block&gt;
                  &lt;fo:block linefeed-treatment="preserve" orphans="4" widows="4"&gt;
                      &lt;xsl:apply-templates select="description"/&gt;
                  &lt;/fo:block&gt;
              &lt;/fo:table-cell&gt;
          &lt;/fo:table-row&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="//description/p"&gt;
          &lt;fo:inline&gt;&lt;xsl:value-of select="text()"/&gt;&lt;/fo:inline&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>EDIT</strong> Added the p-tag to the xml input. I posted the wrong version of xml.</p>