【问题标题】:XSLT FOP PDF table row numberingXSLT FOP PDF 表格行编号
【发布时间】:2021-10-12 00:42:30
【问题描述】:

我正在尝试为仅输出某些行的表获取自动行编号。 示例测试xml

<Data>
<DataRow><Text>red</Text></DataRow>
<DataRow><Text></Text></DataRow>
<DataRow><Text>blue</Text></DataRow>
<DataRow><Text></Text></DataRow>
<DataRow><Text>green</Text></DataRow>

FOP XSLT 摘录

<fo:table width="100%">
    <fo:table-column column-width="8mm"/>
    <fo:table-column column-width="172mm"/>
    <fo:table-body>
        <xsl:for-each select="/Data/DataRow">
            <xsl:if test="string-length(Text) > 0">
                <fo:table-row>
                    <fo:table-cell>
                        <fo:block text-align="left">
                            <xsl:value-of select="position()" /><xsl:text>.</xsl:text>                          
                        </fo:block>     
                    </fo:table-cell>
                    <fo:table-cell>
                        <fo:block text-align="left">
                            <xsl:value-of select="Text" />
                        </fo:block>                     
                    </fo:table-cell>
                </fo:table-row>
            </xsl:if>
        </xsl:for-each>
    </fo:table-body>
</fo:table>     

想要的结果是

1.  red
2.  blue
3.  green

但我得到了

1.  red
3.  blue
5.  green

【问题讨论】:

    标签: xml xslt apache-fop


    【解决方案1】:

    在 for-each 的表达式中使用谓词 Data/DataRow[normalize-space(Text)] 代替嵌套的 if。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 1970-01-01
      • 2019-03-20
      • 2010-12-04
      • 1970-01-01
      相关资源
      最近更新 更多