XSL fo模板性能

时间:2014-10-21 06:54:54

标签: java xslt xslt-1.0 xsl-fo

由于Java堆空间内存错误,

无法处理大量数据的PDF转换(XSLFO到PDF)。

使用FOP1.1,xalan-2.7.1,xercesImpl-2.9.0,serializer-2.9.1 jars进行此过程。 Windows操作系统是32位。 为此过程分配的JVM空间为-Xmx1500M。

有没有其他方法来改善以下xsl代码的性能是否有更好的pdf渲染罐可用..请帮忙。

<fo:table-body>
<xsl:for-each select="MSISDN/ITEM/CALLSUM">
<fo:table-row>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="264.33pt"  reference-orientation="0">

<fo:block-container  reference-orientation="0" >
<fo:block keep-together="auto" ><!-- GENERATE TABLE START-->
<xsl:message>before if</xsl:message>
<xsl:apply-templates match="CALLS[position() mod 2 != 0]"/>
</fo:block>
</fo:block-container>

</fo:table-cell>
<fo:table-cell>
<fo:block-container  reference-orientation="0" >
<fo:block keep-together="auto" >
<xsl:apply-templates match="CALLS[position() mod 2 =0]"/>
</fo:block>
</fo:block-container>
</fo:table-cell>

</fo:table-row>
</xsl:for-each>
</fo:table-body>



<xsl:template match="CALLS[position() mod 2 !=0 ]">
<fo:table table-layout="fixed" width="100%">

<fo:table-column column-width="56.05pt"/>
<fo:table-column column-width="18.0pt"/>
<fo:table-column column-width="71.0pt"/>
<fo:table-column column-width="45.52pt"/>
<fo:table-column column-width="48.37pt"/>
<fo:table-column column-width="25.47pt"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="56.05pt"  reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed"  padding-bottom="0.0pt" start-indent="1.42pt" end-indent="0.0pt" padding-top="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false"  hyphenate="true" language="en"  text-align="start" keep-together="auto"  color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@OPN"/>
</fo:inline>
</fo:block>
</fo:block-container>

</fo:table-cell>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="48.37pt"  reference-orientation="0">

<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed"  padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false"  hyphenate="true" language="en"  text-align="start" keep-together="auto"  color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@CALL_TYPE"/>
</fo:inline>
</fo:block>
</fo:block-container>

</fo:table-cell>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="57.0pt"  reference-orientation="0">

<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed"  padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false"  hyphenate="true" language="en"  text-align="center" keep-together="auto"  color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@DT"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="51.21pt"  reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed"  padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false"  hyphenate="true" language="en"  text-align="center" keep-together="auto"  color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@BILLDUR"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell border-right-style="solid" border-right-width="0.57pt" border-right-color="#000000" padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="31.3pt"  reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed"  padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false"  hyphenate="true" language="en"  text-align="start" keep-together="auto"  color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@AMT"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>

3 个答案:

答案 0 :(得分:0)

我无法想象xsl-fo代码优化可以节省足够的内存,问题似乎是数据量。也许另一个渲染器可能会驱使你离开这个。您可以尝试使用alt-soft的Xml2PDF,它是免费的,适用于Windows。见http://www.alt-soft.com/index/products/xml2pdf-workstation/

答案 1 :(得分:0)

  1. 您不会显示外部表格是使用固定宽度还是自动宽度
  2. 如果你不包括所有属于默认值或继承值的属性,你可以做得更好。
  3. 您的子表看起来像是六列宽,一行深。为什么不直接使用六列(实际上,两列当前列为12列)?如果CALLS的数量可能很奇怪,你将不得不增加一些逻辑,但你更有可能让你的桌子工作。
  4. 您可能必须使用商业FO处理器,例如Antenna House,但他们通常会让您拥有试用许可证,以便您可以在支付软件费用之前查看是否可以执行所需操作

答案 2 :(得分:0)

为了提高XSL的性能,请避免使用xsl:for-each并将其替换为apply-templates。

<table-body>
   <xsl:apply-templates select="MSISDN/ITEM/CALLSUM"/>
</table-body>


<xsl:template match="CALLSUM">
    <!-- The content of the template -->
</xsl:template>