我有一个大型的中世纪手稿转录成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>
这给了我一个像这个页面的成功结果:
我缩小了右侧(结束)以便为保证金备注腾出空间。例如,在第一个<seg>
的第4个<p>
中,有一个保证金说明&#39; Fabri +&#39;。它编码为<add type=margin_gloss>Fabri +</add>
我将以下模板添加到&#39; float&#39;保证金光泽:
<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>
我得到了这场灾难(红色文字/箭头是我对问题的指导)。带浮动的模板做了3件我无法理解的事情。浮子应该&#39;出现在第4段旁边,但是在下面,与下一个<p>
合并;第4 <seg>
消失了;并且以下<p>
的缩进减少了。
答案 0 :(得分:2)
嗯,不是你的答案,因为你使用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>
使用RenderX XEP 时显示浮动Notes的PDF 结果。如果我使用Apache FOP 2.1,它们完全缺失,因为它们中包含float的段落。这完全告诉我FOP不支持这个浮动,你应该联系他们寻求支持。