【问题标题】:XSL - HTML table footer displaying dynamically in position ( changing as per the number of rows in a table )XSL - HTML 表格页脚在位置动态显示(根据表格中的行数更改)
【发布时间】:2018-11-01 08:19:22
【问题描述】:

我有一个嵌入了 HTML 标记的 XSL 表,我使用 Java 从中生成了一个 PDF。我可以使用这个 XSL 样式表生成 PDF。 在我的 XSL 中,我有一个类似的模型:

Page 1:

Header 
 Table
    row 1
    row 2
    row 3
    row 4
    row 5
Footer

Page 2:

Header 
 Table
    row 6
    row 7
    row 8
    row 9
    row 10
Footer

Page 3:

Header 
 Table
    row 11
    row 12
    row 13
Footer

我应该用页眉和页脚显示每页 5 行的表格。问题是,无论表格中的行数如何,我都必须将页脚显示为静态内容。

例如:如果表格包含 5 行或 4 或 3 或 2 或 1 行,页脚应位于页面底部。相反,它会随着表格大小的变化而动态显示在表格下方。

请在下面找到我的 XSL 样式表代码:

<xsl:copy-of select="$Header"/>

<xsl:copy-of select="$OrderRowsHeader"/>

<xsl:for-each select="orders">
    <table style=" width: 100%; height: 13mm;">

        <tr style="font-size: 10px; border: 0">
                        <td width="14mm" style="text-align: right; vertical-align: top;"><xsl:value-of select="number" /></td>
                        <td width="36mm" style=" text-align: left; vertical-align: top;"><xsl:value-of select="code" /></td>
                        <td width="47mm" style=" text-align: left; vertical-align: top;" ><xsl:value-of select="description" /></td>
                        <td width="12mm" style=" text-align: left; vertical-align: top;"><xsl:value-of select="units" /></td>
                        <td width="16mm" style=" text-align: right; vertical-align: top;"><xsl:value-of select="quantity" /></td>
        </tr>
    </table>


    <xsl:if test="(position() mod 5) = 0 and ( position() !=  last() )">

            <xsl:copy-of select="$ReportFooter" />
            <div style="page-break-before: always" />

            <xsl:copy-of select="$Header"/>

            <xsl:copy-of select="$OrderRowsHeader"/>

    </xsl:if>
</xsl:for-each>

<xsl:copy-of select="$ReportFooter" />



<xsl:variable name="ReportFooter">
    <table style="border: solid thin #c0c0c0; border-collapse: collapse; width: 100%; ">
        <tr style="border: solid thin #c0c0c0; border-collapse: collapse;">
            <td width="150mm" style="border: solid thin #c0c0c0; border-collapse: collapse; font-size: 8px;">
            </td> 
                Some Text here......
            </tr>
    </table>
</xsl:variable>

<xsl:variable name="OrderRowsHeader">
    <table style="border: solid thin #c0c0c0; border-collapse: collapse; width: 100%;">

                    <tr style="border: solid thin #c0c0c0; font-size: 9px; border-collapse: collapse;">
                        <th width="18mm" style="border: solid thin #c0c0c0; border-collapse: collapse;">Line</th>
                        <th width="45mm" style="border: solid thin #c0c0c0; border-collapse: collapse;">Product code</th>
                        <th width="63mm" style="border: solid thin #c0c0c0; border-collapse: collapse;">Description</th>
                        <th width="18mm" style="border: solid thin #c0c0c0; border-collapse: collapse;">Units</th>
                        <th width="16mm" style="border: solid thin #c0c0c0; border-collapse: collapse;">Qty</th>
                    </tr>
    </table>
</xsl:variable>

【问题讨论】:

    标签: html xslt xslt-1.0


    【解决方案1】:

    听起来您遇到了样式问题。您的解决方案可在 CSS 中找到。除了与页脚相关的内容外,我不会处理您的任何代码。

    <xsl:variable name="ReportFooter">
        <table style="position: absolute; bottom: 0; border: solid thin #c0c0c0; border-collapse: collapse; width: 100%; ">
            <tr style="border: solid thin #c0c0c0; border-collapse: collapse;">
            <td width="150mm" style="border: solid thin #c0c0c0; border-collapse: collapse; font-size: 8px;">
            </td> 
                Some Text here......
            </tr>
        </table>
    </xsl:variable>
    

    我添加到表中的属性是:position: absolute; bottom: 0;

    position: absolute 会让表格忽略页面的流动(意味着它不会相对于其他元素流动),bottom 是衡量它与页面底部的距离,所以@987654325 @ 会将其放在父容器的底部。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-07
      • 2018-06-11
      • 2021-04-03
      • 1970-01-01
      相关资源
      最近更新 更多