我正在创建一个包含25列的fo:table。 当我转换为PDF时,表格对于页面的大小而言太宽(A4),如何逐列打破表格,例如,我想在另一页面上写入每5列?
由于
答案 0 :(得分: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,通过在&lt; xsl:param name =“columnNumber”/&gt;中传递整数值将其分解为多个表。 PARAM:
<?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>
请查看此内容并检查此示例是否有帮助
答案 1 :(得分: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">
....