title: XSL:FO why is inline is not a valid child of "fo:table"? How can I fix this?
body: <p>Question: How can I resolve this error "XSL:FO inline is not a valid child of "fo:table" ?</p>
  
  <p>Assume that I have a document with a simple table that look like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;diffreport&gt;
  &lt;css /&gt;
  &lt;diff&gt;
      &lt;table border="1" cellpadding="1" cellspacing="1" style="width:500px"&gt;
          &lt;caption&gt;This is the table caption&lt;/caption&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;span class="diff-html-removed" id="removed-diff-0"      previous="first-diff"
                          changeId="removed-diff-0" next="added-diff-0"&gt;one&lt;/span&gt;
                      &lt;span class="diff-html-added" id="added-diff-0" previous="removed-diff-0"
                          changeId="added-diff-0" next="removed-diff-1"&gt;uno&lt;/span&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;span class="diff-html-removed" id="removed-diff-1" previous="added-diff-0"
                          changeId="removed-diff-1" next="added-diff-1"&gt;two&lt;/span&gt;
                      &lt;span class="diff-html-added" id="added-diff-1" previous="removed-diff-1"
                          changeId="added-diff-1" next="last-diff"&gt;dos&lt;/span&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;three&lt;/td&gt;
                  &lt;td&gt;four&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
      &lt;p /&gt;
  &lt;/diff&gt;
  &lt;/diffreport&gt;
  </code></pre>
  
  <p>I have created an xsl:fo template file that looks like this.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsl:stylesheet version="1.0"
  xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="/"&gt;
      &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
          &lt;fo:layout-master-set&gt;
              &lt;fo:simple-page-master master-name="default-page"
                  page-height="11in" page-width="8.5in" margin-left="0.6in"
                  margin-right="0.6in" margin-top="0.79in" margin-bottom="0.79in"&gt;
                  &lt;fo:region-body /&gt;
              &lt;/fo:simple-page-master&gt;
          &lt;/fo:layout-master-set&gt;
          &lt;fo:page-sequence master-reference="default-page"&gt;
              &lt;fo:flow flow-name="xsl-region-body"&gt;
                  &lt;fo:block&gt;
                      &lt;fo:block font-size="180%" font-weight="bold" text-align="center"&gt;
                          &lt;xsl:text&gt;Report&lt;/xsl:text&gt;
                      &lt;/fo:block&gt;
                      &lt;fo:block&gt;
                          &lt;xsl:apply-templates /&gt;
                      &lt;/fo:block&gt;
  
                  &lt;/fo:block&gt;
              &lt;/fo:flow&gt;
          &lt;/fo:page-sequence&gt;
      &lt;/fo:root&gt;
  &lt;/xsl:template&gt;
  &lt;!-- xsl report colors --&gt;
  &lt;xsl:template match="span[@class='diff-html-added']"&gt;
      &lt;fo:inline color="green" background-color="#ccffcc"&gt;
          &lt;xsl:value-of select="." /&gt;
      &lt;/fo:inline&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="span[@class='diff-html-removed']"&gt;
      &lt;fo:inline color="red" text-decoration="line-through"
          background-color="#fdc6c6"&gt;
          &lt;xsl:value-of select="." /&gt;
      &lt;/fo:inline&gt;
  &lt;/xsl:template&gt;
  
  &lt;!-- Table --&gt;
  &lt;xsl:template match="table"&gt;
      &lt;xsl:apply-templates /&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="tbody"&gt;
      &lt;fo:table space-before="0.5em" space-after="0.5em"
          table-layout="fixed"&gt;
          &lt;xsl:for-each select="tr[1]/th|tr[1]/td"&gt;
              &lt;xsl:apply-templates /&gt;
          &lt;/xsl:for-each&gt;
          &lt;fo:table-body&gt;
              &lt;xsl:apply-templates /&gt;
          &lt;/fo:table-body&gt;
      &lt;/fo:table&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="tr"&gt;
      &lt;fo:table-row&gt;
          &lt;xsl:if test="@space-before != ''"&gt;
              &lt;xsl:attribute name="space-before"&gt;&lt;xsl:value-of select="@space-before" /&gt;&lt;/xsl:attribute&gt;
          &lt;/xsl:if&gt;
          &lt;xsl:if test="@class='graybar'"&gt;
              &lt;xsl:attribute name="background-color"&gt;#ddd&lt;/xsl:attribute&gt;
          &lt;/xsl:if&gt;
          &lt;xsl:apply-templates /&gt;
      &lt;/fo:table-row&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="th"&gt;
      &lt;fo:table-cell font-weight="bold" text-align="center"&gt;
          &lt;xsl:if test="ancestor::table/@border &amp;gt; 0"&gt;
              &lt;xsl:attribute name="border-style"&gt;solid&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="border-width"&gt;1pt&lt;/xsl:attribute&gt;
          &lt;/xsl:if&gt;
          &lt;fo:block&gt;
              &lt;xsl:apply-templates /&gt;
          &lt;/fo:block&gt;
      &lt;/fo:table-cell&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="td"&gt;
      &lt;fo:table-cell&gt;
          &lt;xsl:if test="ancestor::table/@border &amp;gt; 0"&gt;
              &lt;xsl:attribute name="border-style"&gt;solid&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="border-width"&gt;1pt&lt;/xsl:attribute&gt;
          &lt;/xsl:if&gt;
          &lt;fo:block&gt;
              &lt;xsl:call-template name="set-alignment" /&gt;
              &lt;xsl:apply-templates /&gt;
          &lt;/fo:block&gt;
      &lt;/fo:table-cell&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="set-alignment"&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="@align='left' or contains(@class,'left')"&gt;
              &lt;xsl:attribute name="text-align"&gt;start&lt;/xsl:attribute&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="@align='center' or contains(@class,'center')"&gt;
              &lt;xsl:attribute name="text-align"&gt;center&lt;/xsl:attribute&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:when test="@align='right' or contains(@class,'right')"&gt;
              &lt;xsl:attribute name="text-align"&gt;end&lt;/xsl:attribute&gt;
          &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I keep getting this error
  <strong>(Location of error unknown)org.apache.fop.fo.ValidationException: "{<a href="http://www.w3.org/1999/XSL/Format" rel="nofollow">http://www.w3.org/1999/XSL/Format</a>}inline" is not a valid child of "fo:table"! (No context info available)</strong></p>
  
  <p>If I remove these blocks of code from the xsl the error goes away, but I really need help to figure out why this code does not work.</p>
  
  <pre><code>  &lt;xsl:template match="span[@class='diff-html-added']"&gt;
       &lt;span style="color:green; background-color: #ccffcc;"&gt;
       &lt;xsl:value-of select="."/&gt;&lt;/span&gt;
   &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Why is inline not a child of "fo:table"?
  What do I need to do to fix my xsl template so that my span classes will work in a table?</p>