向 XSL-FO 文档添加行号

Adding line numbers to XSL-FO document

我有一个已转换为 XSL-FO 的 word 文档 (.doc),以便我可以添加用户的输入,但转换不是最好的,所以我正在修改 FO 以匹配原始文件word文档。 Word 文档在每一页的左侧都有行号。 See screenshot of original .doc file. I found this 由于 Dimitre Novatchev 的回答,文章有些用处,但我在他的解决方案中遇到了 Stack Overflow 异常。 AH 先生有一个很好的解决方案,但我不喜欢手动将行号添加到每一页上的每一行的想法。每页有28行。

我可以做一些类似于页眉或页脚的事情吗?

或者用图像创建行号并在每一页上插入图像是否有意义?

我正在使用 Apache 的 FOP 1.0 库,Java 在后台驱动。 (不能升级到 2.0)

我的 .fo 文件:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format"       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xml:space="preserve">
<xsl:strip-space elements="fo:inline"/>
<fo:root xmlns:myHelper="com.my.path.XslHelper"
     xmlns:svg="http://www\.w3\.org/2000/svg"
     xmlns:exsl="http://xmlns.opentechnology.org/xslt-extensions/common" 
     xmlns:fo="http://www.w3.org/1999/XSL/Format" 
     xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
     xmlns:st1="urn:schemas-microsoft-com:office:smarttags" >
<fo:layout-master-set xmlns:rx="http://www.renderx.com/XSL/Extensions" 
                    xmlns:o="urn:schemas-microsoft-com:office:office" 
                    xmlns:v="urn:schemas-microsoft-com:vml" 
                    xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" 
                    xmlns:aml="http://schemas.microsoft.com/aml/2001/core" 
                    xmlns:w10="urn:schemas-microsoft-com:office:word" 
                    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<fo:simple-page-master master-name="simple" page-width="8.5in" page-height="11in" margin-top=".5in" margin-bottom=".3in" margin-left=".75in" margin-right=".7in">
  <fo:region-body region-name="xsl-region-body" margin-top=".50in" margin-bottom=".5in"/>
  <fo:region-before region-name="xsl-region-before" extent="5in"/>
  <fo:region-after region-name="xsl-region-after" extent=".5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence xmlns:rx="http://www.renderx.com/XSL/Extensions"
                xmlns:o="urn:schemas-microsoft-com:office:office"
                xmlns:v="urn:schemas-microsoft-com:vml"
                xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
                xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
                xmlns:w10="urn:schemas-microsoft-com:office:word"
                xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
                master-reference="simple"
                id="IDDEWVO12VGWFHFXTK2ROJBGP3HLXLWHRYZMPQZ5NGVSECKDMKHTTH"
                format="1">
<fo:static-content flow-name="xsl-region-before">
    <fo:block></fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after"> 
    <fo:block text-align="center"><fo:page-number/></fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" font-family="TimesNewRoman" font-size="12pt" line-height="1.7205" language="EN-US">
  <fo:block widows="2" orphans="2" white-space-collapse="false" break-after="page">
      <xsl:variable name="confidentialChecked"><xsl:choose><xsl:when test="$livingTogether = 'Yes'">[x]</xsl:when><xsl:otherwise>[ ]</xsl:otherwise></xsl:choose></xsl:variable>
      <fo:inline>2.<xsl:value-of select="$spacer"/>My address is: <xsl:value-of select="$confidentialChecked"/> </fo:inline><fo:inline font-weight="bold" text-decoration="underline">CONFIDENTIAL</fo:inline><fo:inline> (If confidential, do not write address here)</fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <fo:inline>Address: <xsl:value-of select="concat($pl1_addressLine1, ' ', $pl1_addressLine2)"/></fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <fo:inline>City: <xsl:value-of select="$pl1_city"/> State: <xsl:value-of select="$pl1_state"/> Zip: <xsl:value-of select="$pl1_postalCode"/></fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <xsl:variable name="ownRent"><xsl:choose><xsl:when test="$pl1_ownOrRent = 'Own'">[x] own [ ] rent</xsl:when><xsl:when test="$pl1_ownOrRent = 'Rent'">[ ] own [x] rent</xsl:when><xsl:otherwise>[ ] own [ ] rent</xsl:otherwise></xsl:choose></xsl:variable>
      <fo:inline>I <xsl:value-of select="$ownRent"/> this residence. Lease/title is held in all the following name(s):</fo:inline>
    </fo:block>
    <fo:block text-indent="36pt">
      <fo:inline><xsl:value-of select="$pl1_residenceLeaseNames"/></fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <fo:inline>How long have you been living in this residence? <xsl:value-of select="$pl1_timeAtResidence"/></fo:inline>
    </fo:block>
  </fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

我对所有这些 FO 都是新手,所以请让我知道您需要什么其他信息来帮助我解决这个问题。提前致谢!

您的图像显示的是标尺,而不是实际的物理行号。行号将与文本对齐,您的图像仅显示一组等距的数字内容。

您可以通过多种方式轻松创建类似的内容,这里有一些 FO 供您参考以供参考。您可以调整间距、大小,甚至可以使用数学来计算这些东西的需求。

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:rx="http://www.renderx.com/XSL/Extensions">
<fo:layout-master-set>
    <fo:simple-page-master page-width="8.5in" page-height="11in" master-name="master">
        <fo:region-body margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in"/>
        <fo:region-before extent="11in"/>
    </fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="master">
    <fo:static-content flow-name="xsl-region-before">
        <fo:block-container margin-left="0.15in" margin-top="0.5in" line-height="26pt" width="12pt" text-align="right">
            <fo:block>1</fo:block>
            <fo:block>2</fo:block>
            <fo:block>3</fo:block>
            <fo:block>4</fo:block>
            <fo:block>5</fo:block>
            <fo:block>6</fo:block>
            <fo:block>7</fo:block>
            <fo:block>8</fo:block>
            <fo:block>9</fo:block>
            <fo:block>10</fo:block>
            <fo:block>11</fo:block>
            <fo:block>12</fo:block>
            <fo:block>13</fo:block>
            <fo:block>14</fo:block>
            <fo:block>15</fo:block>
            <fo:block>16</fo:block>
            <fo:block>17</fo:block>
            <fo:block>18</fo:block>
            <fo:block>19</fo:block>
            <fo:block>20</fo:block>
            <fo:block>21</fo:block>
            <fo:block>22</fo:block>
            <fo:block>23</fo:block>
            <fo:block>24</fo:block>
            <fo:block>25</fo:block>
            <fo:block>26</fo:block>
            <fo:block>27</fo:block>
            <fo:block>28</fo:block>
        </fo:block-container>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body">
        <fo:block>Test</fo:block>
        <fo:block space-before="12pt">Eos sed aliquam diam sanctus duis facilisis clita. Euismod accusam eu blandit autem dolores ullamcorper illum amet molestie et sadipscing sea et ut dolore stet dolor. Ullamcorper invidunt stet hendrerit lorem ex clita ipsum luptatum elitr aliquyam accusam vero. Voluptua sadipscing nonumy ea sit consequat et et diam amet vulputate. Nulla ea odio duo consetetur elitr stet eos. Stet amet aliquyam duis.</fo:block>
        <fo:block space-before="12pt">Eos sed aliquam diam sanctus duis facilisis clita. Euismod accusam eu blandit autem dolores ullamcorper illum amet molestie et sadipscing sea et ut dolore stet dolor. Ullamcorper invidunt stet hendrerit lorem ex clita ipsum luptatum elitr aliquyam accusam vero. Voluptua sadipscing nonumy ea sit consequat et et diam amet vulputate. Nulla ea odio duo consetetur elitr stet eos. Stet amet aliquyam duis.</fo:block>
        <fo:block space-before="12pt">Eos sed aliquam diam sanctus duis facilisis clita. Euismod accusam eu blandit autem dolores ullamcorper illum amet molestie et sadipscing sea et ut dolore stet dolor. Ullamcorper invidunt stet hendrerit lorem ex clita ipsum luptatum elitr aliquyam accusam vero. Voluptua sadipscing nonumy ea sit consequat et et diam amet vulputate. Nulla ea odio duo consetetur elitr stet eos. Stet amet aliquyam duis.</fo:block>
    </fo:flow>
</fo:page-sequence>
</fo:root>

这会在 FOP 中产生此输出:

普通的单程 XSL-FO 进程无法生成行编号。没有命令支持这个。正如 Kevin 在他的示例中所展示的那样,很难将固定行号与高度可变的文本对齐。

有些格式化程序使用扩展来支持行编号:例如,Antennahouse Formatter 有 axf:line-number extension