有没有办法在XSL-FO中使用等效的'rowspan'?

时间:2009-11-11 07:51:29

标签: xslt xsl-fo

我想在<fo:table>的最左侧列中显示字体较大的文字。但是,右边的列应该包含几行文本较小的行。

这是在添加任何最左边的列和更大的文本之前XSL代码的样子:

<xsl:template name="printAddress">
  <xsl:param name="subDocument" />
  <fo:table table-layout="fixed" background-color="#e0e0e0" keep-with-next.within-page="always">
    <fo:table-column column-width="7.0cm" />
    <fo:table-column column-width="7.0cm" />
    <fo:table-column column-width="2.0cm" />
    <fo:table-body>
      <!-- Begin Row 1 -->
      <fo:table-row keep-with-previous="always">
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block>Value 1</fo:block>
        </fo:table-cell>
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block>Value 2</fo:block>
        </fo:table-cell>
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block />
        </fo:table-cell>
      </fo:table-row>
      <!-- Begin Row 2 -->
      <fo:table-row keep-with-previous="always">
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block>
            <xsl:value-of select="$subDocument/someAttribute" />
          </fo:block>
        </fo:table-cell>
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block>
            <xsl:value-of select="$subDocument/someOtherAttribute" />
          </fo:block>
        </fo:table-cell>
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block />
        </fo:table-cell>
      </fo:table-row>
      <!-- Begin Row 3 -->
      <fo:table-row keep-with-previous="always">
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block>value 3</fo:block>
        </fo:table-cell>
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block>Value 4</fo:block>
        </fo:table-cell>
        <fo:table-cell margin-left="0.2cm" padding-before="0.1cm" padding-after="0.1cm">
          <fo:block>Value 5</fo:block>
        </fo:table-cell>
      </fo:table-row>
    </fo:table-body>
  </fo:table>
</xsl:template>

我想在左侧添加一列但我找不到它的语法。在HTML中,上面的内容将是这样的:

<tr>
    <td>Value 1</td>
    <td>Value 2</td>
    <td></td>
</tr>   
<tr>
    <td>{someAttribute}</td>
    <td>{someOtherAttribute}</td>
    <td></td>
</tr>   
<tr>
    <td>Value 3</td>
    <td>Value 4</td>
    <td>Value 5</td>
</tr>

为了实现我想要的目标,我们只需要像这样修改它:

<tr>
    <td rowspan="3" style="font-weight:bold;font-size:14pt">New Text</td>
    <td>Value 1</td>
    <td>Value 2</td>
    <td></td>
</tr>   
<tr>
    <td>{someAttribute}</td>
    <td>{someOtherAttribute}</td>
    <td></td>
</tr>   
<tr>
    <td>Value 3</td>
    <td>Value 4</td>
    <td>Value 5</td>
</tr>

但对于XSL-FO,最好如何做到这一点?

3 个答案:

答案 0 :(得分:34)

<fo:table-cell number-rows-spanned="3">

难道你不喜欢罗嗦的XSL吗?

答案 1 :(得分:4)

上面选择的答案是正确的,你将“number-rows-spanned =”子句添加到表格单元格的定义中。

但是,与HTML不同,您不会在下面的跨区行中留下占位符单元格。如果你这样做,FO会抱怨行中定义了太多的单元格。

答案 2 :(得分:0)

使用number-rows-spanned或number-column-spanned。但为什么不使用视觉设计师呢? 我正在使用Ecrion XF Designer并且它做得非常好。