繁体   English   中英

XSL-FO分页符,寡妇和孤儿

[英]XSL-FO page breaks, widows and orphans

我有一个大型语料库,它基于以下简化的XML结构的XSL-FO 3.0转换生成PDF:

<corpus>
  <deposition>
     <text>
       <deposition-title>foo title</deposition-title>
       <seg>foo paragraph 1</seg>
       <seg>foo paragraph 2</seg>
       <seg>foo paragraph 3</seg>
       <appnotes>
         <appitem>foo apparatus item 1</appitem>
       </appnotes>
       <footnotes>
         <footitem>foo note 1</footitem>
         <footitem>foo note 1</footitem>
       </footnotes>
     </text>
  </deposition>
  <deposition>
     <text>
       <deposition-title>foo title</deposition-title>
       <seg>foo paragraph 1</seg>
       <seg>foo paragraph 2</seg>
      <appnotes/>
       <footnotes>
         <footitem>foo note 1</footitem>
       </footnotes>
     </text>
  </deposition>
   [...]
</corpus>

我使用的XSL-FO 3.0如下所示(减去上标和斜体的一些内联标记):

<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" 
xmlns:xd="http://www.pnp-software.com/XSLTdoc"
version="3.0">

<xsl:template match="/">
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master 
                master-name="page-recto"
                page-height="29.7cm"  page-width="21cm"
                margin-top="2cm" margin-bottom="2cm" 
                margin-left="3cm" margin-right="1.5cm">
                <fo:region-body 
                    region-name="xsl-region-body"/>
            </fo:simple-page-master>
        </fo:layout-master-set>

        <fo:page-sequence master-reference="page-recto">
            <fo:flow flow-name="xsl-region-body" 
                font-family="Times" font-weight="normal" 
                font-size="8pt" space-before="8pt" space-after="8pt"
                text-align="justify" end-indent="120pt">
                <xsl:apply-templates/>
            </fo:flow>
        </fo:page-sequence>

    </fo:root>
</xsl:template>

<xsl:template match="text">
    <fo:block widows="10" orphans="10"
        font-size="9pt" font-weight="bold" 
        padding-bottom="1cm" end-indent="120pt">
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>


<xsl:template match="seg">
    <fo:block
        font-family="Times" font-weight="normal" line-height="12pt" line-stacking-strategy="font-height"
        font-size="10pt" space-before="10pt" space-after="10pt" text-align="justify" end-indent="120pt">
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>

<xsl:template match="appnotes">
   <xsl:choose>
       <xsl:when test="./appitem">
            <fo:leader leader-pattern="rule" leader-length="2cm" rule-style="solid" rule-thickness=".2pt"/>      
            <fo:block font-size="8pt" font-weight="normal" end-indent="120pt">
                <xsl:for-each select="./appitem">
                    <fo:inline keep-together="always"><xsl:apply-templates/>&#160;&#160;&#160;</fo:inline>
                </xsl:for-each>
            </fo:block></xsl:when>
       <xsl:otherwise></xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template match="footnotes">
    <xsl:choose>
        <xsl:when test="./footitem">
            <fo:leader leader-pattern="rule" leader-length="2cm" rule-style="solid" rule-thickness=".2pt"/>  
                <xsl:for-each select="./footitem">
                    <fo:block font-size="8pt" font-weight="normal" end-indent="120pt">
                       <xsl:apply-templates/>
                    </fo:block>
                </xsl:for-each>
            <fo:leader leader-pattern="rule" leader-length="2cm" rule-style="solid" rule-thickness=".2pt"/>      
        </xsl:when>
        <xsl:otherwise>
            <fo:leader leader-pattern="rule" leader-length="2cm" rule-style="solid" rule-thickness=".2pt"/>      
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
</xsl:stylesheet>

它会产生可重复的部分,如下所示:

好的输出,没有坏的分页符

但是XSL-FO产生了一些分页符问题,使用保持在一起,寡妇,孤儿等的组合,我似乎无法解决这些问题。

<deposition-title><seg>断开

标题与内容分开

<seg><appnotes><footnotes> <appnotes>

内容与应用注释/脚注分开

目标:我想应用以下两个规则来分页任何<text>

  1. <deposition-title>坚持第一个<seg>

  2. <appnotes><footnotes>坚持最后的<seg>

预先感谢您的任何见解。

如果添加

<xsl:template match="deposition-title">
    <fo:block keep-with-next="always">
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>

那么标题应与您生成的第一个段块放在同一页面上。

应用笔记和脚注应该采用与keep-with-previous类似的构造,据我所知,您希望将它们与最后一个seg块一起保存,因此也许应该在模板匹配text更改<xsl:apply-templates/>更改为<xsl:apply-templates select="node() except footnotes/> ,然后在模板匹配的appnotes ,创建包装器并处理脚注,例如

<xsl:template match="appnotes">
  <fo:block keep-with-previous="always">
    ...
    <xsl:apply-templates select="following-sibling::footnotes"/>
  </fo:block>
</xsl:template>

在接受答案的后续活动中,我将在此处发布针对注释中标识的一个问题的修订代码。 现在<appnotes><footnotes>是一个模板,位于一个<fo:block> 这是使用RenderX处理的。

<xsl:template match="footnotes | appnotes">
    <fo:block font-size="8pt" font-weight="normal" end-indent="120pt" keep-with-previous="always">
        <xsl:choose>
            <xsl:when test="./appitem">
                <fo:leader leader-pattern="rule" leader-length="2cm" rule-style="solid" rule-thickness=".2pt" keep-with-previous="always"/>      
                <fo:block keep-with-previous="always">
                    <xsl:for-each select="./appitem">
                        <fo:inline><xsl:apply-templates/>&#160;&#160;&#160;</fo:inline>
                    </xsl:for-each>
                </fo:block>
            </xsl:when>
        </xsl:choose>
        <xsl:choose>
            <xsl:when test="./footitem">
                <fo:leader leader-pattern="rule" leader-length="2cm" rule-style="solid" rule-thickness=".2pt" keep-with-previous="always"/>  
                <xsl:for-each select="./footitem">
                    <fo:block keep-with-previous="always">
                        <xsl:apply-templates/>
                    </fo:block>
                </xsl:for-each>     
                <fo:leader leader-pattern="rule" leader-length="2cm" rule-style="solid" rule-thickness=".2pt" keep-with-previous="always"/> 
            </xsl:when>
        </xsl:choose>
    </fo:block>
</xsl:template>

暂无
暂无

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

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