title: PDF report with embedded HTML
body: <p>We have a Java-based system that reads data from a database, merges individual data fields with preset <code>XSL-FO</code> tags and converts the result to <code>PDF</code> with <code>Apache FOP</code>.</p>
  
  <p>In <code>XSL-FO</code> format it looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;!DOCTYPE Html [
  &lt;!ENTITY nbsp  "&amp;#160;"&gt; 
      &lt;!-- all other entities --&gt;
  ]&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
      &lt;xsl:output method="xml" indent="yes" /&gt;
      &lt;xsl:template match="/"&gt;
  
          &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" font-family="..." font-size="..."&gt;
              &lt;fo:layout-master-set&gt;          
                  &lt;fo:simple-page-master master-name="Letter Page" page-width="8.500in" page-height="11.000in"&gt;
  
                      &lt;!-- appropriate settings --&gt;
  
                  &lt;/fo:simple-page-master&gt;
              &lt;/fo:layout-master-set&gt;
              &lt;fo:page-sequence master-reference="Letter Page"&gt;
  
                  &lt;!-- some static content --&gt;
  
              &lt;fo:flow flow-name="xsl-region-body"&gt;
                      &lt;fo:block&gt;
                          &lt;fo:table ...&gt;
                              &lt;fo:table-column ... /&gt;
                              &lt;fo:table-body&gt;
                                  &lt;fo:table-row&gt;
                                      &lt;fo:table-cell ...&gt;
                                          &lt;fo:block text-align="..."&gt;
                                              &lt;fo:inline font-size="..." font-weight="..."&gt;
                                                  &lt;!-- Header / Title --&gt;
                                              &lt;/fo:inline&gt;
                                          &lt;/fo:block&gt;
                                      &lt;/fo:table-cell&gt;
                                  &lt;/fo:table-row&gt;
                              &lt;/fo:table-body&gt;
                          &lt;/fo:table&gt;
                      &lt;/fo:block&gt;
  
                      &lt;fo:block&gt;
  
                          &lt;fo:table ...&gt;
                              &lt;fo:table-column ... /&gt;
                              &lt;fo:table-body&gt; 
                                  &lt;fo:table-row&gt;
                                      &lt;fo:table-cell&gt;
                                          &lt;fo:block ...&gt;
                                              &lt;!-- Field A --&gt;                                
                                          &lt;/fo:block&gt;
                                      &lt;/fo:table-cell&gt;
                                  &lt;/fo:table-row&gt;
                              &lt;/fo:table-body&gt;
                          &lt;/fo:table&gt;
  
                          &lt;!-- Other fields in a very similar fashion as the above "Field A" --&gt;
  
                      &lt;/fo:block&gt;
  
                  &lt;/fo:flow&gt;      
  
              &lt;/fo:page-sequence&gt;
  
          &lt;/fo:root&gt;              
  
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Now I am looking for a way to allow some of the fields to contain static <strong>HTML-formatted</strong> content.  This content will be generated by our HTML-enabled editor (something along the lines of <code>CLEditor</code>, <code>CKEditor</code>, etc.) or pasted from outside.</p>
  
  <p>My plan is to follow the recipe <a href="http://www.javaworld.com/article/2071749/java-app-dev/convert-html-content-to-pdf-format.html">from this JavaWorld article</a>:</p>
  
  <ul>
  <li>use <code>JTidy</code> to convert HTML-formatted string to proper XHTML  </li>
  <li>further modify <a href="http://www.antennahouse.com/XSLsample/sample-xsl-xhtml2fo/xhtml2fo.xsl">xhtml2fo.xsl</a> from Antenna House to remove all document-wide and page-wide transformations</li>
  <li>apply this modified XSLT to my XHTML string (javax.xml.transform)</li>
  <li>extract all the nodes under the root with XPath (javax.xml.xpath)</li>
  <li>feed the result directly into existing XSL-FO document</li>
  </ul>
  
  <p>I have a bare-bone version of such code and got the following error:</p>
  
  <blockquote>
    <p>(Location of error unknown)org.apache.fop1.fo.ValidationException:
    "{<a href="http://www.w3.org/1999/XSL/Format">http://www.w3.org/1999/XSL/Format</a>}table-body" is not a valid child
    of "fo:block"! (No context info available)</p>
  </blockquote>
  
  <p>My questions:</p>
  
  <ol>
  <li>What would be the way to troubleshoot this issue?</li>
  <li>Can <code>&lt;fo:block&gt;</code> serve as a generic container with other objects (including tables) nested inside?</li>
  <li>Is this an overall reasonable approach to solving the task?</li>
  </ol>
  
  <p>If someone already "<em>been there done that</em>", please share your experience.</p>