XSL-FO:在每个之间强制分页。

发布于 2024-10-11 21:25:45 字数 1726 浏览 8 评论 0原文

我正在尝试使用 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 中的所有单独的modspec 之间添加分页符?

编辑 http://www.sagehill.net/docbookxsl/PageBreaking.html 我应该添加的状态将其添加到我的 XSLT:

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

以便它在 .xml 文件中获取 。我希望使解决方案尽可能紧凑,那么如何编辑样式表,以便第一遍在每个 < 之后添加 xi:include> 后跟给定我的 sagehill 的模板?

I'm trying to generate a mod spec with pdf generation. The way I have it be generated is using a contents.xml file which looks like this...

<?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>

Now I also have a stylesheet that sets header, footer, and table style stuff before the above xml is sent off for XSL-FO, and this stylesheet will need to add the page breaks.

So my question is: How do do I add a page break between all my sperate modspecs in contents.xml?

EDIT
http://www.sagehill.net/docbookxsl/PageBreaking.html States I should add this to my XSLT:

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

So that it picks up <?hard-pagebreak?> in the .xml files. I would like to keep the solution as compact as possible, so how do I edit my stylesheet so that a first pass will add the <?hard-pagebreak?> after each <xi:include> followed by the template given my sagehill?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔小萌 2024-10-18 21:25:45

此样式表:

<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>

因此,您可以将匹配虚构 硬分页处理指令的模板添加到到 DocBook 到 FOP 样式表中

This stylesheet:

<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>

Output:

<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>

So, then you can add that template matching fictitious hard-pagebreak processing instruction into the DocBook to FOP stylesheet

萝莉病 2024-10-18 21:25:45

要在输出中强制分页,您应该直接手动添加 处理指令到 XML 源文档(与您已经添加的方式相同)添加了 ),并放入

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

样式表自定义层。如果您愿意,您可以使用 @Alejandro 的建议,该建议使用额外的转换步骤添加 PI,但您实际上并不需要(恕我直言)。

To force page breaks in the output, the idea is that you should add <?hard-pagebreak?> processing instructions directly, by hand, to the XML source document (the same way you have already added <?dbfo-need height="8in" space-before="3em"?>), and put

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

in the stylesheet customization layer. If you want, you could use @Alejandro's suggestion which adds the PIs using an extra transformation step, but you don't really need that (IMHO).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文