2014-12-04 44 views
0

我使用FOP 1.1爲了從xml文檔生成pdf文件。 FOP文檔在這裏http://xmlgraphics.apache.org/fop/如何正確地允許頁面中斷在fop xml中?

pdf文檔生成正常。但是,我一直在收到這個嚴重警告信息。我不知道如何解決這個問題。

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) 

我有以下代碼

<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> 
+0

你最有可能有一個 'BR' 元素沒有'break'屬性,因此'break-after'屬性最終爲空。 – 2014-12-04 00:30:50

+0

嗯你是什麼意思?我對此並不怎麼看好。你可以給我一個例子嗎? – 2014-12-04 01:09:05

回答

1

xsl:template您顯示,該break-after屬性具有這個屬性值模板:{@break}

這意味着@break的值將被用於值break-after。如果沒有@break,則不會有任何值(這似乎是您的問題)。

看看你的XML輸入;是否有br元素沒有break屬性(//br[not(@break)])?

是否真的有br元素break屬性(//br[@break])?

你可以做的是修改你的模板來處理兩者。輸出一個默認值,如page,如果有break屬性用該值覆蓋默認值。

您不指定XSLT的版本,因此我將給出(未經測試的)1.0和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> 

另一個XSLT 1.0選項

<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>