FOP中动态表中的生成单元格

时间:2014-05-22 07:14:22

标签: xml pdf xsl-fo apache-fop xmltable

我的问题是我有一个动态长度的表,我需要在3个单元格上跨越3行,其他行具有单个单元格长度。

我得到一个生成的XML文件,其值为

<item>
  <val1>a</val1>
  <val2>b</val2>
  <val3_1>a1</val3_1>
  <val3_2>b1</val3_2>
  <val3_3>c1</val3_3>
  <val4>c</val4>
</item>

表格看起来像

 | val1: |-------val1---------| |-------val1---------|
 | val2: |-------val2---------| |-------val2---------|
 | val3: |val3_1|val3_2|val3_3| |val3_1|val3_2|val3_3|
 | val4: |--------val4--------| |--------val4--------|

我有这个来源:

<fo:table width="100%" table-layout="fixed">
<fo:table-body>

    <fo:table-row>
        <fo:table-cell border-style="solid" border-width="1pt"
            background-color="{$tabbgcolor}" width="50mm">
            <fo:block>
                               val1:
            </fo:block>
        </fo:table-cell>
        <xsl:for-each select="item">
            <fo:table-cell border-style="solid"
                number-columns-spanned="3" border-width="2pt" background-color="{$tabbgcolor}"
                font-weight="bold" text-align="center">
                <fo:block>
                    <xsl:value-of select="val1" />
                </fo:block>
            </fo:table-cell>
        </xsl:for-each>
    </fo:table-row>

    <fo:table-row>
        <fo:table-cell border-style="solid" border-width="1pt"
            background-color="{$var_color_reserve}">
            <fo:block text-indent="1em" wrap-option="wrap">
                val2:
            </fo:block>
        </fo:table-cell>
        <xsl:for-each select="item">
            <fo:table-cell border-style="solid"
                number-columns-spanned="3" border-width="2pt" background-color="{$tabbgcolor}"
                text-align="center">
                <fo:block>
                    <xsl:value-of select="val2" />
                </fo:block>
            </fo:table-cell>
        </xsl:for-each>
    </fo:table-row>

    <fo:table-row>
        <fo:table-cell border-style="solid" border-width="1pt"
            background-color="{$var_color_reserve}">
            <fo:block text-indent="1em" wrap-option="wrap">
                Val3:
            </fo:block>
        </fo:table-cell>


        <xsl:for-each select="item">
            <fo:table-cell border-style="solid" border-width="2pt"
                background-color="{$tabbgcolor}" text-align="center">
                <fo:block wrap-option="wrap">
                    <xsl:value-of select="val3_1" />
                </fo:block>
            </fo:table-cell>
        </xsl:for-each>

        <xsl:for-each select="item">
            <fo:table-cell border-style="solid" border-width="2pt"
                background-color="{$tabbgcolor}" text-align="center">
                <fo:block wrap-option="wrap">
                    <xsl:value-of select="val3_2" />
                </fo:block>
            </fo:table-cell>
        </xsl:for-each>

        <xsl:for-each select="instzahl">
            <fo:table-cell border-style="solid" border-width="2pt"
                background-color="{$tabbgcolor}" text-align="center">
                <fo:block wrap-option="wrap">
                    <xsl:value-of select="val3_3" />
                </fo:block>
            </fo:table-cell>
        </xsl:for-each>




    </fo:table-row>

    <fo:table-row>
        <fo:table-cell border-style="solid" border-width="1pt"
            background-color="{$var_color_reserve}">
            <fo:block text-indent="1em" wrap-option="wrap">
                val4:
            </fo:block>
        </fo:table-cell>
        <xsl:for-each select="item">
            <fo:table-cell border-style="solid"
                number-columns-spanned="3" border-width="2pt" background-color="{$tabbgcolor}"
                text-align="center">
                <fo:block>
                    <xsl:value-of select="val4" />
                </fo:block>
            </fo:table-cell>
        </xsl:for-each>
    </fo:table-row>


</fo:table-body>

问题如下:

  1. 错误地解析了这些值:我得到所有值val3_1然后是所有val3_2然后所有val3_3而不是val3_1 val3_2 val3_3和下一个转向val3_1 val3_2 val3_3等等。

  2. 跨越不起作用。我知道这是因为我现在不会有多少单元格,因为我无法预见xml文件生成时会有多少项目。

  3. 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

好的,我在这里解决的是代码:

                    <fo:table-body>

                        <fo:table-row>
                            <fo:table-cell border-style="solid" border-width="1pt"  width="50mm">
                                <fo:block>
                                  val1: 
                                </fo:block>
                            </fo:table-cell>
                            <xsl:for-each select="item">
                                <fo:table-cell border-style="solid" number-columns-spanned="3"  border-width="2pt" font-weight="bold" text-align="center">
                                    <fo:block>
                                        <xsl:value-of select="val1" />
                                    </fo:block>
                                </fo:table-cell>
                        </xsl:for-each>
                        </fo:table-row>

                        <fo:table-row>
                            <fo:table-cell border-style="solid" border-width="1pt" >
                                <fo:block  wrap-option="wrap">
                                     val2:
                                </fo:block>
                            </fo:table-cell>
                            <xsl:for-each select="item">
                                <fo:table-cell border-style="solid" number-columns-spanned="3" border-width="2pt" text-align="center">
                                    <fo:block>
                                        <xsl:value-of select="val2" />
                                    </fo:block>
                                </fo:table-cell>
                            </xsl:for-each>
                        </fo:table-row>

                        <fo:table-row>
                            <fo:table-cell border-style="solid" border-width="2pt" >
                                <fo:block  wrap-option="wrap">
                                    val3:
                                </fo:block>
                            </fo:table-cell>


                            <xsl:for-each select="item">
                                <fo:table-cell border-style="solid" border-width="1pt" text-align="center">
                                    <fo:block wrap-option="wrap">
                                        <xsl:value-of select="val3_1" />
                                    </fo:block>
                                </fo:table-cell>

                            <fo:table-cell border-style="solid"  border-width="1pt" text-align="center">
                                    <fo:block wrap-option="wrap">
                                        <xsl:value-of select="val3_2" />
                                    </fo:block>
                                </fo:table-cell>

                                <fo:table-cell border-style="solid" border-width="1pt"  text-align="center">
                                    <fo:block wrap-option="wrap">
                                        <xsl:value-of select="val3_3" />
                                    </fo:block>
                                </fo:table-cell>
                            </xsl:for-each>


                        </fo:table-row>


                        <fo:table-row>
                            <fo:table-cell border-style="solid" border-width="2pt" >
                                <fo:block  wrap-option="wrap">
                                    val4
                                </fo:block>
                            </fo:table-cell>
                        <xsl:for-each select="item">
                                <fo:table-cell border-style="solid" number-columns-spanned="3" border-width="2pt" text-align="center">
                                    <fo:block>
                                        <xsl:value-of select="val4" />
                                    </fo:block>
                                </fo:table-cell>
                        </xsl:for-each>
                        </fo:table-row>


                    </fo:table-body>
                </fo:table>