繁体   English   中英

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

[英]XSL-FO: Forcing a page break between each <xi:include>

我正在尝试使用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>

现在,我还有一个样式表,用于在为XSL-FO发送上述xml之前设置页眉,页脚和表格样式的内容,并且此样式表将需要添加分页符。

所以我的问题是:如何在contents.xml的所有精巧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?> 我想使解决方案尽可能紧凑,那么如何编辑样式表,以便第一遍将在每个<xi:include>之后添加<?hard-pagebreak?> ,然后添加给我的鼠尾草模板?

此样式表:

<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 to FOP样式表中

要在输出中强制使用分页符,您的想法是应该手动将<?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,但是您实际上并不需要它(IMHO)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM