Search code examples
xmlapache-fop

How to properly allow page break in fop xml?


I am using FOP 1.1 in order to generate pdf file from xml documents. FOP documentation is here http://xmlgraphics.apache.org/fop/

The pdf document is generated fine. However, I keep on getting this SEVERE warning message. I have no clue how to fix this.

SEVERE: Invalid property value encountered in break-after="": org.apache.fop.fo.expr.PropertyException: No conversion defined ; property:'break-after' (No context info available)
org.apache.fop.fo.expr.PropertyException: No conversion defined ; property:'break-after'
        at org.apache.fop.fo.properties.PropertyMaker.make(PropertyMaker.java:446)
        at org.apache.fop.fo.PropertyList.convertAttributeToProperty(PropertyList.java:413)
        at org.apache.fop.fo.PropertyList.addAttributesToList(PropertyList.java:321)
        at org.apache.fop.fo.FObj.processNode(FObj.java:122)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:280)
        at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:175)
        at org.apache.xml.serializer.ToXMLSAXHandler.closeStartTag(ToXMLSAXHandler.java:204)
        at org.apache.xml.serializer.ToSAXHandler.flushPending(ToSAXHandler.java:277)
        at org.apache.xml.serializer.ToXMLSAXHandler.endElement(ToXMLSAXHandler.java:243)
        at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1399)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:139)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:339)
        at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:288)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:339)
        at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:288)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:339)
        at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:288)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:339)
        at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:288)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:339)
        at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:288)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:339)
        at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:288)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
        at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
        at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
        at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:300)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:130)
        at org.apache.fop.cli.Main.startFOP(Main.java:177)
        at org.apache.fop.cli.Main.main(Main.java:208)

I have the following codes

  <xsl:template match="br">
    <fo:block break-after="{@break}"></fo:block>
  </xsl:template>


<xsl:attribute-set name="page.break">
    <xsl:attribute name="break-after">page</xsl:attribute>
</xsl:attribute-set>

Solution

  • In the xsl:template that you are showing, the break-after attribute has this attribute value template: {@break}.

    This means that the value of @break is going to be used for the value of break-after. If there is no @break, there will be no value (which appears to be your issue).

    Look at your XML input; are there br elements with no break attributes (//br[not(@break)])?

    Are there really br elements with break attributes (//br[@break])?

    What you could do is modify your template to handle both. Output a default value, like page, and if there is a break attribute override your default value with that value.

    You don't specify what version of XSLT, so I'll give (untested) examples for both 1.0 and 2.0.

    XSLT 2.0

    <xsl:template match="br">
        <fo:block break-after="{if (string(@break)) then @break else 'page'}"/>        
    </xsl:template>
    

    XSLT 1.0

    <xsl:template match="br">
        <fo:block break-after="page">
            <xsl:apply-templates select="@break[string()]"/>
        </fo:block>
    </xsl:template>
    
    <xsl:template match="br/@break">
        <xsl:attribute name="break-after">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>
    

    Another XSLT 1.0 option

    <xsl:template match="br">
        <fo:block break-after="page">
            <xsl:if test="string(@break)">
                <xsl:attribute name="break-after">
                    <xsl:value-of select="@break"/>
                </xsl:attribute>
            </xsl:if>
        </fo:block>
    </xsl:template>