XSL:FO 用于显示边注的浮动 - 中断文档

XSL:FO float for displaying margin notes - breaks document

我有一份大型中世纪手稿转录成 XML(使用 TEI 模式)。我正在使用 xsl:fo 和 Apache FOP 处理成 PDF。该文件是使用嵌套 <body><p><seg> 构建的,如下所示。偶尔 <add> 用于边注。

<body>
   <p>
    <title>title here</title>
    <seg>Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
        Quisque a orci non mauris convallis imperdiet consequat nec 
        purus. Cras mollis lacus vel lectus facilisis, non
        hendrerit velit tempor. Phasellus tempor urna vel accumsan 
        dignissim.</seg>
    <seg>Aliquam porta eu nunc sed laoreet. 
        Sed<add type='margin_gloss'>Some margin note here</add> 
        non nulla consectetur, lobortis tortor ac,
        placerat nunc. Nulla viverra finibus est nec efficitur. Donec 
        nisi nisl, tincidunt dapibus purus pretium, rhoncus volutpat 
        tortor. Cras fringilla tellus tortor, at
        ultricies mi cursus at. Nulla facilisi.</seg>
    <seg>Quisque id mi nisl. In in mauris id leo malesuada hendrerit. 
        Orci varius natoque
        penatibus et magnis dis parturient montes, nascetur ridiculus 
        mus. Nulla sit amet
        commodo mauris.</seg>
  </p>
</body>

xml 文件很大,因此有一个主 xml 文件使用 <xi:include> 将数百个这样的文件组成完整的手稿。

我已按照以下基本说明成功将其处理成 PDF:

  <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="2cm" margin-right="1cm">
                <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="body/p">
     <fo:block 
         page-break-inside="avoid"
         font-size="9pt" font-weight="bold" 
         padding-bottom="1cm" end-indent="120pt">
         <xsl:value-of select="tei:title"/>
         <xsl:apply-templates/>
     </fo:block>
   </xsl:template>


   <xsl:template match="seg">
      <fo:block id="@xml:id"
          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:block>
    </xsl:template>

这给了我一个成功的结果,就像这个页面:

我将右侧(末尾)缩进以便为边注腾出空间。比如第一个<p>的第4个<seg>,有一个边注'Fabri +'。它被编码为 <add type=margin_gloss>Fabri +</add>

我将以下模板添加到 'float' 边距光泽:

<xsl:template match="body/p//add[@type='margin_gloss']">
     <fo:float float="end">
            <fo:block-container>
                <fo:block>
                    <xsl:value-of select="./s/text()"/>
                </fo:block>
            </fo:block-container>
        </fo:float>

</xsl:template>

我遇到了这个灾难(红色 text/arrows 是我的问题指南)。带浮动的模板做了 3 件我无法理解的事情。浮动 'should' 出现在第 4 段旁边,但在下方,与下一个 <p> 合并;第 4 个 <seg> 消失了;并且减少了以下 <p> 的缩进。

嗯,这不是适合您的答案,因为您使用的是 FOP,而且它对浮点数的支持非常有限。我以你为例,用内容扩展了一点,并删除了一些奇怪的东西,比如像你那样设置 ID。

这个XML:

<body>
<p>
    <title>title here</title>
    <seg>1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
        Quisque a orci non mauris convallis imperdiet consequat nec 
        purus. Cras mollis lacus vel lectus facilisis, non
        hendrerit velit tempor. Phasellus tempor urna vel accumsan 
        dignissim.</seg>
    <seg>2 note Aliquam porta eu nunc sed laoreet. 
        Sed<add type='margin_gloss'>Some margin note here</add> 
        non nulla consectetur, lobortis tortor ac,
        placerat nunc. Nulla viverra finibus est nec efficitur. Donec 
        nisi nisl, tincidunt dapibus purus pretium, rhoncus volutpat 
        tortor. Cras fringilla tellus tortor, at
        ultricies mi cursus at. Nulla facilisi.</seg>
    <seg>3 Quisque id mi nisl. In in mauris id leo malesuada hendrerit. 
        Orci varius natoque
        penatibus et magnis dis parturient montes, nascetur ridiculus 
        mus. Nulla sit amet
        commodo mauris.</seg>
    <seg>4 Quisque id mi nisl. In in mauris id leo malesuada hendrerit. 
        Orci varius natoque
        penatibus et magnis dis parturient montes, nascetur ridiculus 
        mus. Nulla sit amet
        commodo mauris.</seg>
    <seg>5 Quisque id mi nisl. In in mauris id leo malesuada hendrerit. 
        Orci varius natoque
        penatibus et magnis dis parturient montes, nascetur ridiculus 
        mus. Nulla sit amet
        commodo mauris.</seg>
    <seg>6 note Aliquam porta eu nunc sed laoreet. 
        Sed<add type='margin_gloss'>Some margin note here 2</add> 
        non nulla consectetur, lobortis tortor ac,
        placerat nunc. Nulla viverra finibus est nec efficitur. Donec 
        nisi nisl, tincidunt dapibus purus pretium, rhoncus volutpat 
        tortor. Cras fringilla tellus tortor, at
        ultricies mi cursus at. Nulla facilisi.</seg>
    <seg>7 Quisque id mi nisl. In in mauris id leo malesuada hendrerit. 
        Orci varius natoque
        penatibus et magnis dis parturient montes, nascetur ridiculus 
        mus. Nulla sit amet
        commodo mauris.</seg>
    <seg>8 Quisque id mi nisl. In in mauris id leo malesuada hendrerit. 
        Orci varius natoque
        penatibus et magnis dis parturient montes, nascetur ridiculus 
        mus. Nulla sit amet
        commodo mauris.</seg>
</p>
</body>

使用此 XSL 处理:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" 
version="1.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="2cm" margin-right="1cm">
                <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="body/p">
    <fo:block 
        page-break-inside="avoid"
        font-size="9pt" font-weight="bold" 
        padding-bottom="1cm" end-indent="120pt">
        <xsl:value-of select="title"/>
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>

<xsl:template match="add">
    <fo:inline font-style="italic">
        <xsl:apply-templates/>
    </fo:inline>
</xsl:template>

<xsl:template match="seg">
    <fo:block
        font-family="Times" font-weight="normal"
        font-size="8pt" space-before="8pt"
        space-after="8pt" text-align="justify"
        end-indent="2.5in">
        <xsl:if test="descendant::add[@type='margin_gloss']">
            <fo:float float="right">
                <fo:block-container width="2in" border="1pt solid black" margin="10pt">
                    <fo:block>
                        <xsl:apply-templates select="add[@type='margin_gloss']"/>
                    </fo:block>
                </fo:block-container>
            </fo:float>
        </xsl:if>
        <xsl:apply-templates select="text()"/>
    </fo:block>
</xsl:template>
</xsl:stylesheet>

此 PDF 中的结果使用 RenderX XEP 时显示您的浮动笔记。如果我使用 Apache FOP 2.1,它们就会完全丢失,因为它们中有浮动的段落。这完全向我表明 FOP 不支持此浮动,您应该联系他们寻求支持。