如何在fop xsl-fo中使用'white-space'属性?

时间:2019-04-05 12:41:57

标签: apache-fop

我正在使用FOP 2.2,以便从xml文档生成pdf文件。 FOP文档在这里http://xmlgraphics.apache.org/fop/

pdf文档生成良好。但是,我不断收到此错误消息。

    ERROR: Invalid property value encountered in white-space="pre-wrap": org.apache.fop.fo.expr.PropertyException: null:118:-1: No conversion defined pre-wrap; property:'white-space' (See position 119:-1)
org.apache.fop.fo.expr.PropertyException: null:118:-1: No conversion defined pre-wrap; property:'white-space'
    at org.apache.fop.fo.properties.PropertyMaker.make(PropertyMaker.java:446)
    at org.apache.fop.fo.PropertyList.convertAttributeToProperty(PropertyList.java:499)
    at org.apache.fop.fo.PropertyList.addAttributesToList(PropertyList.java:386)
    at org.apache.fop.fo.FObj.processNode(FObj.java:124)
    at org.apache.fop.fo.flow.table.TableFObj.processNode(TableFObj.java:232)
    at org.apache.fop.fo.flow.table.TableRow.processNode(TableRow.java:82)
    at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.startElement(FOTreeBuilder.java:291)
    at org.apache.fop.fo.FOTreeBuilder.startElement(FOTreeBuilder.java:179)
    at net.sf.saxon.event.ContentHandlerProxy.startContent(ContentHandlerProxy.java:252)
    at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:169)
    at net.sf.saxon.event.NamespaceReducer.startContent(NamespaceReducer.java:187)
    at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:195)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:262)
    at net.sf.saxon.event.Sender.send(Sender.java:128)
    at net.sf.saxon.IdentityTransformer.transform(IdentityTransformer.java:28)

xsl模板具有以下代码:

<xsl:attribute name="style">
    <xsl:text>white-space: pre-wrap;</xsl:text>
</xsl:attribute>

1 个答案:

答案 0 :(得分:0)

(我想您正在使用XSLT将HTML转换为XSL-FO,因为style不是有效的FO属性)

错误消息告诉您pre-wrap不是属性white-space的有效值;唯一允许的值为normalprenowrap

但是,在XSL-FO white-space中,它只是一个“速记属性”,可以快速控制与空白相关的一组属性,因此您应该能够直接设置这些属性来获得所需的结果:

linefeed-treatment="preserve" 
white-space-collapse="false" 
white-space-treatment="preserve"