XSL-FO:在每个<xi:include> </xi:include>之间强制分页

时间:2011-01-12 22:55:51

标签: xml xslt xsl-fo docbook

我正在尝试使用pdf生成生成mod规范。我生成它的方式是使用一个看起来像这样的contents.xml文件......

<?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="http://docbook.org/ns/docbook http://schema.5d.ca/docbook/docbook.xsd
                    http://www.w3.org/2001/XInclude http://schema.5d.ca/docbook/XInclude.xsd">

<title>Mod Spec</title>
<?dbfo-need height="8in" space-before="3em" ?>
<xi:include href="first.xml"/>    
<section>
    <title>View Stuff</title>
    <xi:include href="./stuff/panel.xml"/>
</section>
<section>
    <title>Nav things</title>
    <xi:include href="./things/about.xml"/>        
    <xi:include href="./things/control.xml"/>
    <xi:include href="./things/launch.xml"/>        
</section>
...(more sections with includes)
</article>

现在我还有一个样式表,在上面的xml被发送到XSL-FO之前设置页眉,页脚和表样式的东西,这个样式表需要添加分页符。

所以我的问题是:如何在contents.xml中的所有sperate modspecs之间添加分页符?

修改 http://www.sagehill.net/docbookxsl/PageBreaking.html状态我应该将它添加到我的XSLT中:

<xsl:template match="processing-instruction('hard-pagebreak')">
   <fo:block break-after='page'/>
</xsl:template>

这样它就可以在.xml文件中获取<?hard-pagebreak?>。我想让解决方案尽可能紧凑,那么如何编辑我的样式表以便第一遍将在每个<?hard-pagebreak?>之后添加<xi:include>,然后在我的sagehill上添加模板?

2 个答案:

答案 0 :(得分:3)

此样式表:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xi="http://www.w3.org/2001/XInclude">
    <xsl:template match="@*|node()" name="identity">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="xi:include">
        <xsl:call-template name="identity"/>
        <xsl:processing-instruction name="hard-pagebreak"/>
    </xsl:template>
</xsl:stylesheet>

输出:

<article xsi:schemaLocation=
          "http://docbook.org/ns/docbook http://schema.5d.ca/docbook/docbook.xsd
           http://www.w3.org/2001/XInclude http://schema.5d.ca/docbook/XInclude.xsd"
         xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:xi="http://www.w3.org/2001/XInclude">
    <title>Mod Spec</title>
    <?dbfo-need height="8in" space-before="3em" ?>
    <xi:include href="first.xml"></xi:include>
    <?hard-pagebreak?>
    <section>
        <title>View Stuff</title>
        <xi:include href="./stuff/panel.xml"></xi:include>
        <?hard-pagebreak?>
    </section>
    <section>
        <title>Nav things</title>
        <xi:include href="./things/about.xml"></xi:include>
        <?hard-pagebreak?>
        <xi:include href="./things/control.xml"></xi:include>
        <?hard-pagebreak?>
        <xi:include href="./things/launch.xml"></xi:include>
        <?hard-pagebreak?>
    </section> ...(more sections with includes) 
</article>

那么,您可以将 虚拟 hard-pagebreak处理说明的模板添加到DocBook到FOP样式表

答案 1 :(得分:2)

要在输出中强制分页,我们的想法是您应该手动将<?hard-pagebreak?>处理指令直接添加到XML源文档中(与您已添加<?dbfo-need height="8in" space-before="3em"?>的方式相同),并把

<xsl:template match="processing-instruction('hard-pagebreak')">
  <fo:block break-after='page'/>  
</xsl:template> 
样式表自定义层中的

。如果你愿意,你可以使用@Alejandro的建议,使用额外的转换步骤添加PI,但你真的不需要(恕我直言)。