0

我正在创建一个包含 25 列的 fo:table。当我转换为 PDF 时,表格对于页面 (A4) 的大小来说太宽了,如何按列拆分表格,例如,我想在另一页上写每 5 列?

谢谢

4

2 回答 2

0

我举了一个表的例子,它有九列,如:

<Table>
  <thead>
    <tr>
      <td>Head1</td>
      <td>Head2</td>
      <td>Head3</td>
      <td>Head4</td>
      <td>Head5</td>
      <td>Head6</td>
      <td>Head7</td>
      <td>Head8</td>
      <td>Head9</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>5</td>
      <td>6</td>
      <td>7</td>
      <td>8</td>
      <td>9</td>
    </tr>
    <tr>
      <td>2-1</td>
      <td>2-2</td>
      <td>2-3</td>
      <td>2-4</td>
      <td>2-5</td>
      <td>2-6</td>
      <td>2-7</td>
      <td>2-8</td>
      <td>2-9</td>
    </tr>
    <tr>
      <td>3-1</td>
      <td>3-2</td>
      <td>3-3</td>
      <td>3-4</td>
      <td>3-5</td>
      <td>3-6</td>
      <td>3-7</td>
      <td>3-8</td>
      <td>3-9</td>
    </tr>
  </tbody>
</Table>

现在,我创建了 XSLT,通过在 <xsl:param name="columnNumber"/> 参数中传递整数值将其分解为多个表:

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xsl:output indent="yes"/>

  <xsl:param name="columnNumber" select="xs:integer(4)"/>

  <xsl:template match="Table">
    <xsl:param name="countColumn" select="count(//tbody/tr[1]/td)"/>
    <xsl:choose>
      <xsl:when test="$countColumn gt $columnNumber">
        <xsl:call-template name="divideTable">
          <xsl:with-param name="tableToGenerate" select="ceiling($countColumn div $columnNumber)"/>
          <xsl:with-param name="orginialTable" select="self::*"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy>
          <xsl:copy-of select="*"/>
        </xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="divideTable">
    <xsl:param name="tableToGenerate"/>
    <xsl:param name="orginialTable"/>
    <xsl:param name="start" select="xs:integer(1)"/>
    <xsl:param name="end" select="$columnNumber"/>
    <xsl:param name="counter" select="xs:integer(1)"/>
    <xsl:choose>
      <xsl:when test="$counter le $tableToGenerate">
        <Table>
          <thead>
            <xsl:copy-of
              select="$orginialTable/thead/tr/td[position() le $end and position() ge $start]"/>
          </thead>
          <tbody>
            <xsl:for-each select="$orginialTable/tbody/tr">
              <tr>
                <xsl:copy-of select="td[position() le $end and position() ge $start]"/>
              </tr>
            </xsl:for-each>
          </tbody>
        </Table>
        <xsl:call-template name="divideTable">
          <xsl:with-param name="start" select="xs:integer(($columnNumber * $counter) + 1)"/>
          <xsl:with-param name="end" select="xs:integer(($columnNumber * $counter) + $columnNumber)"/>
          <xsl:with-param name="tableToGenerate" select="$tableToGenerate"/>
          <xsl:with-param name="orginialTable" select="$orginialTable"/>
          <xsl:with-param name="counter" select="xs:integer($counter + 1)"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

它给了我输出:

<?xml version="1.0" encoding="UTF-8"?>
<Table xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <thead>
      <td>Head1</td>
      <td>Head2</td>
      <td>Head3</td>
      <td>Head4</td>
   </thead>
   <tbody>
      <tr>
         <td>1</td>
         <td>2</td>
         <td>3</td>
         <td>4</td>
      </tr>
      <tr>
         <td>2-1</td>
         <td>2-2</td>
         <td>2-3</td>
         <td>2-4</td>
      </tr>
      <tr>
         <td>3-1</td>
         <td>3-2</td>
         <td>3-3</td>
         <td>3-4</td>
      </tr>
   </tbody>
</Table>
<Table xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <thead>
      <td>Head5</td>
      <td>Head6</td>
      <td>Head7</td>
      <td>Head8</td>
   </thead>
   <tbody>
      <tr>
         <td>5</td>
         <td>6</td>
         <td>7</td>
         <td>8</td>
      </tr>
      <tr>
         <td>2-5</td>
         <td>2-6</td>
         <td>2-7</td>
         <td>2-8</td>
      </tr>
      <tr>
         <td>3-5</td>
         <td>3-6</td>
         <td>3-7</td>
         <td>3-8</td>
      </tr>
   </tbody>
</Table>
<Table xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <thead>
      <td>Head9</td>
   </thead>
   <tbody>
      <tr>
         <td>9</td>
      </tr>
      <tr>
         <td>2-9</td>
      </tr>
      <tr>
         <td>3-9</td>
      </tr>
   </tbody>
</Table>

请看看这个并检查这个例子是否有帮助

于 2013-04-18T07:22:40.553 回答
0

我的解决方案是创建两个独立的表。然后我创建了两个 xsl 模板块,以区分我使用模式功能的第二个块的第一个块。像这样:

Table
....
<xsl:apply-templates select="content[@teste='1']" mode="first" />
....
<xsl:apply-templates select="content[@teste='1']" mode="second" />
....
XSL Templates block
....
<xsl:template match="content[@teste='1']" mode="first">
....
<xsl:template match="content[@teste='1']" mode="second">
....
于 2013-04-21T15:18:32.217 回答