2

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

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

4

2 回答 2

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

于 2011-01-13T00:24:24.073 回答
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,但您并不真正需要(恕我直言)。

于 2011-01-13T18:35:01.657 回答