XSL-FO问题与分页符

时间:2015-11-01 21:28:37

标签: xslt xsl-fo

我正在尝试使用课程信息渲染pdf。我需要一个在生成内容之前打破新页面的目录。在目录之后我需要同时生成内容,这意味着每个课程都没有分页。但是,我的代码正确生成了toc,但每个课程都在一个单独的页面上。我需要列出所有课程而不分页。请帮忙。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:attribute-set name="normal">
    <xsl:attribute name="font-family">'Times New Roman', Times, serif</xsl:attribute>
    <xsl:attribute name="font-size">10pt</xsl:attribute>
    <xsl:attribute name="line-height">16pt</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="header">
    <xsl:attribute name="font-size">8pt</xsl:attribute>
    <xsl:attribute name="text-align">end</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="footer">
    <xsl:attribute name="font-size">8pt</xsl:attribute>
    <xsl:attribute name="text-align">end</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="toc">
    <xsl:attribute name="font-family">'Times New Roman', Times, serif</xsl:attribute>
    <xsl:attribute name="font-size">12pt</xsl:attribute>
    <xsl:attribute name="line-height">12pt</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="bold">
    <xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="title">
    <xsl:attribute name="font-family">'Times New Roman', Times, serif</xsl:attribute>
    <xsl:attribute name="font-size">28pt</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="text-align">center</xsl:attribute>
    <xsl:attribute name="padding">0.25em</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="subtitle">
    <xsl:attribute name="font-family">'Times New Roman', Times, serif</xsl:attribute>
    <xsl:attribute name="font-size">24pt</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="text-align">center</xsl:attribute>
    <xsl:attribute name="padding">0.25em</xsl:attribute>
    <xsl:attribute name="break-before">page</xsl:attribute>
</xsl:attribute-set>
<xsl:variable name="title" select="'Courses'"/>
<xsl:template match="/">
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master master-name="main" page-height="11in" page-width="8.5in" margin-top="0.5in" margin-bottom="0.5in" margin-left="1in" margin-right="1in">
                <fo:region-body margin-top="0.5in" margin-bottom="0.5in"/>
                <fo:region-before extent="0.5in"/>
                <fo:region-after extent="0.5in"/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="main"><!-- fo:static-content for header -->
            <fo:static-content flow-name="xsl-region-before">
                <fo:block xsl:use-attribute-sets="normal header">
                    <xsl:text>Courses, Page </xsl:text>
                    <fo:page-number/>
                    <xsl:text> of </xsl:text>
                    <fo:page-number-citation ref-id="EndOfDoc"/>
                </fo:block>
            </fo:static-content>
            <fo:flow flow-name="xsl-region-body"><!-- This is the "main" content --><!-- title -->
                <fo:block>
                    <fo:block xsl:use-attribute-sets="title">
                        <xsl:value-of select="$title"/>
                    </fo:block><!-- main content through apply-templates -->
                    <xsl:apply-templates/>
                </fo:block><!-- give empty block at end a known id
        go get total page numbers -->
                <fo:block id="EndOfDoc"/>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
</xsl:template><!-- "courses" is root element -->
<xsl:template match="courses">
    <xsl:apply-templates select="course" mode="toc"/>
    <xsl:apply-templates select="course"/>
</xsl:template>
<xsl:template match="course">
    <fo:block id="{generate-id()}" xsl:use-attribute-sets="subtitle">
        <xsl:value-of select="catalog_info/title/@short_title"/>
    </fo:block>
</xsl:template>
<xsl:template match="course" mode="toc"><!-- Table of Contents -->
    <fo:block text-align-last="justify" xsl:use-attribute-sets="toc">
        <fo:basic-link internal-destination="{generate-id()}">
            <xsl:value-of select="catalog_info/title/@short_title"/>
            <xsl:text>, </xsl:text>
            <xsl:value-of select="catalog_info/title"/>
        </fo:basic-link>
        <fo:leader leader-pattern="dots"/>
        <fo:page-number-citation>
            <xsl:attribute name="ref-id">
                <xsl:value-of select="generate-id()"/>
            </xsl:attribute>
        </fo:page-number-citation>
    </fo:block>
</xsl:template>

1 个答案:

答案 0 :(得分:1)

每个课程的内容都从新页面的开头开始,因为匹配course的模板会创建一个包含"subtitle"属性集的块,其中包含break-before="page"

你需要:

  • 从属性集
  • 中删除该属性
  • 在内容列表之后执行某些操作以启动新页面,例如在调用<xsl:apply-templates select="course"/>之前使用break属性的空块;一个更好的解决方案可能是创建两个不同的页面序列,一个用于目录,另一个用于内容
相关问题