在XSL-FO文档中添加行号

时间:2018-11-30 22:14:19

标签: xml xslt-1.0 xsl-fo line-numbers

我有一个Word文档(.doc),我已经将其转换为XSL-FO,以便可以添加用户的输入,但是转换不是最大的,因此我正在修改FO以匹配原始的Word文档。 。 Word文档的行号在每一页的左侧。 See screenshot of original .doc file。多亏了Dimitre Novatchev的回答,我发现this的文章有些用处,但是他的解决方案得到了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知识都是陌生的,所以请让我知道您需要其他什么信息来帮助我。预先感谢!

2 个答案:

答案 0 :(得分:0)

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

您可以通过几种方式轻松地创建类似的东西,这里有一些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形式输出:

{{0}}

答案 1 :(得分:0)

正常的单次XSL-FO处理无法产生行号。没有支持此功能的命令。正如Kevin在他的示例中所示,将固定行号与高度可变的文本对齐确实很困难。

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

相关问题