我正在使用以下lib / namespaces从xml生成pdf
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:math="http://exslt.org/math"
xmlns:exslt="http://exslt.org/common"
xmlns:str="http://exslt.org/strings"
exclude-result-prefixes="exslt math str">
我的要求是我要打印一些文本fo:block-container文本将打印在第二页上。
<fo:block-container xsl:use-attribute-sets="section border_red">
<fo:block xsl:use-attribute-sets="header">Product:</fo:block>
<xsl:for-each select="ROWSET2/ROWSET2_ROW">
<fo:block xsl:use-attribute-sets="paragraph indented"><xsl:value-of select="PRODUCTNAME"/></fo:block>
</xsl:for-each>
<!-- when page not first print something at the end of this block -->
</fo:block-container>
因此,当块溢出到2ed,3ed ..页面时,如果块在第一页上完成,则不需要在文本上打印,因此可以在块内进行打印。
尝试过“ fo:retrieve-table-marker”
:
<fo:table>
<fo:table-header>
<fo:table-cell>
<fo:block xsl:use-attribute-sets="header">Product:
</fo:block>
</fo:table-cell>
</fo:table-header>
<fo:table-footer>
<fo:table-row>
<fo:table-cell>
<fo:retrieve-table-marker
retrieve-class-name="test123" retrieve-boundary-within-table="table"
retrieve-position-within-table="last-starting" />
</fo:table-cell>
</fo:table-row>
</fo:table-footer>
<fo:table-body>
<xsl:for-each select="ROWSET2/ROWSET2_ROW">
<xsl:choose>
<xsl:when test="position() != last()">
<fo:table-row>
<fo:marker marker-class-name="test123">To be continued...
</fo:marker>
<fo:table-cell>
<fo:block xsl:use-attribute-sets="paragraph indented">
<xsl:value-of select="PRODUCTNAME" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:when>
<xsl:otherwise>
<fo:table-row>
<fo:marker marker-class-name="test123"></fo:marker>
<fo:table-cell>
<fo:block xsl:use-attribute-sets="paragraph indented">
<xsl:value-of select="PRODUCTNAME" />
last
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</fo:table-body>
</fo:table>
答案 0 :(得分:2)
如果当fo:block-container分成多个页面时,您的要求是在页面末尾输出特殊文本,那么XSL 1.1和XSL-FO处理器供应商的扩展中就没有这样的功能(据我所知)。
但是,如果您使用fo:table,fo:table-footer,fo:retrieve-table-marker和fo:marker使用表外部规则,并且每行都没有规则,则在以下情况下可以输出特殊文本:表分成多页。
[XSL 1.1] 6.7.7 fo:table-footer
[XSL 1.1] 6.13.7 fo:retrieve-table-marker =“
请参阅以下博客文章(日语)中的示例快照:
テーブルのタイトルに"(Continued)"と出す. (3)
在此示例中,“继续下一页”在fo:table-cell的fo:marker中定义,并通过fo:retrieve-table-marker在fo:table-footer中显示。
示例数据:
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<ROWSET2>
<ROWSET2_ROW><PRODUCTNAME>Product1</PRODUCTNAME></ROWSET2_ROW>
<ROWSET2_ROW><PRODUCTNAME>Product2</PRODUCTNAME></ROWSET2_ROW>
...
<ROWSET2_ROW><PRODUCTNAME>Product24</PRODUCTNAME></ROWSET2_ROW>
<ROWSET2_ROW><PRODUCTNAME>Product25</PRODUCTNAME></ROWSET2_ROW>
</ROWSET2>
</ROOT>
示例代码:
<xsl:template match="ROOT">
<fo:table width="100%">
<fo:table-header>
<fo:table-cell>
<fo:block xsl:use-attribute-sets="header">Product:
</fo:block>
</fo:table-cell>
</fo:table-header>
<fo:table-footer>
<fo:table-row>
<fo:table-cell>
<fo:retrieve-table-marker
retrieve-class-name="test123"/>
</fo:table-cell>
</fo:table-row>
</fo:table-footer>
<fo:table-body>
<xsl:for-each select="ROWSET2/ROWSET2_ROW">
<fo:table-row>
<fo:table-cell>
<fo:block xsl:use-attribute-sets="paragraph indented">
<xsl:choose>
<xsl:when test="position() = 1">
<fo:marker marker-class-name="test123">
<fo:block xsl:use-attribute-sets="indented" color="teal">To be continued...</fo:block>
</fo:marker>
</xsl:when>
<xsl:when test="position() = last()">
<fo:marker marker-class-name="test123"/>
</xsl:when>
</xsl:choose>
<xsl:value-of select="PRODUCTNAME" />
<xsl:if test="position()=last()">
<fo:inline> Last</fo:inline>
</xsl:if>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:template>
样本结果:
答案 1 :(得分:0)
找到的解决方案: 以下代码正在使用Apache fop2.3
当我在true
内使用<fo:inline>
时,它便起作用了。
<fo:marker>