Search code examples
xsl-fo

xsl-fo empty table body (validation exception)


I am using the following transformation to create a table from XML

<fo:table table-layout="fixed" width="100%">
    <fo:table-header>
        <fo:table-row text-align="right" font-weight="bold">
            <fo:table-cell column-number="2" text-align="center">
                <fo:block>ColA</fo:block>
            </fo:table-cell>
            <fo:table-cell column-number="3" text-align="center">
                <fo:block>Name</fo:block>
            </fo:table-cell>
            <fo:table-cell column-number="4">
                <fo:block color="red">ColB</fo:block>
            </fo:table-cell>
            <fo:table-cell column-number="5" text-align="center"
                color="red">
                <fo:block width="1cm">%</fo:block>
            </fo:table-cell>
        </fo:table-row>
    </fo:table-header>
    <fo:table-body>
        <xsl:apply-templates select="list/v" />
    </fo:table-body>
</fo:table>

For short, I create one row per "list/v"
My problem is, is there is no corresponding data, I am getting the following exception

org.apache.fop.fo.ValidationException: "fo:table-body" is missing child elements. Required content model: marker* (table-row+|table-cell+) (No context info available)


Hence my question : How do you create a valid table without body when no data is available?


Solution

  • The following worked evetually:

    <fo:table table-layout="fixed" width="100%">
        <fo:table-header> (unchanged) </fo:table-header>
        <fo:table-body>
            <xsl:if test="list/v">
                <xsl:apply-templates select="list/v" />
            </xsl:if>
            <xsl:if test="not(list/v)">
                <fo:table-cell><fo:block /></fo:table-cell>
            </xsl:if>
        </fo:table-body>
    </fo:table>