是否有可能在XSLT/XSL FO中显示一个运行总数?



我试图格式化一个报告,我有表格,将跨越多个页面的各种项目/费用,我想做的是在表脚中显示每个页面的运行总数,基本上我想在我的表中值的总和从当前页面回到第一页显示在底部。有什么办法可以做到这一点吗?

<fo:table width="100%" border-style="groove" border-width="2pt" background-repeat="repeat">
  <fo:table-column column-width="5%" />
  <fo:table-column column-width="60%" />
  <fo:table-column column-width="5%" />
  <fo:table-column column-width="7.5%" />
  <fo:table-column column-width="7.5%" />
  <fo:table-column column-width="7.5%" />
  <fo:table-column column-width="7.5%" />
  <fo:table-footer border-top-style="dashed" border-bottom-style="dashed">
    <fo:table-cell display-align="center">
    </fo:table-cell>
    <fo:table-cell display-align="center">
      <fo:block text-align="center">
        Page <fo:page-number/>
        <xsl:text> OF </xsl:text>
        <fo:page-number-citation ref-id="end" />
      </fo:block>
    </fo:table-cell>
    <fo:table-cell display-align="center">
    </fo:table-cell>
    <fo:table-cell display-align="center">
    </fo:table-cell>
    <fo:table-cell display-align="center">
    </fo:table-cell>
    <fo:table-cell display-align="center">
      <fo:block text-align="end">
        Page Total:
      </fo:block>
    </fo:table-cell>
    <fo:table-cell display-align="center">
    </fo:table-cell>
  </fo:table-footer>
  <fo:table-body>
    <xsl:for-each select="/receipt_invoice/details/product_lot">
      <xsl:variable name="untitled" select="." />
      <fo:table-row>
        <fo:table-cell border-style="solid" border-width="1pt" border-color="black" padding="2pt" background-repeat="repeat" display-align="center">
          <fo:block text-align="right">
            <fo:block>
              <xsl:value-of select="lot/quantity" />
            </fo:block>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="1pt" border-color="black" padding="2pt" background-repeat="repeat" display-align="center">
          <fo:block>
            <fo:table width="100%" border-style="none" border-width="2pt" background-repeat="repeat">
              <fo:table-column/>
              <fo:table-column/>
              <fo:table-body>
                <fo:table-row>
                  <fo:table-cell border-style="none" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="before">
                    <fo:block>
                      <fo:block>
                        <xsl:value-of select="product/code" />
                      </fo:block>
                      <fo:block>
                        Lot Qty:
                        <xsl:value-of select="lot/quantity" />
                      </fo:block>
                      <fo:block>
                        <xsl:text>
                          &#xA0;
                        </xsl:text>
                      </fo:block>
                      <fo:block>
                        <xsl:value-of select="lot/identifier" />
                      </fo:block>
                      <fo:block>
                        <xsl:value-of select="lot/lot_components/component/label" />
                      </fo:block>
                      <fo:block>
                        <xsl:value-of select="lot/lot_components/component/value" />
                      </fo:block>
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell border-style="none" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="before">
                    <fo:block>
                      <fo:block>
                        <xsl:value-of select="product/first_description" />
                      </fo:block>
                      <fo:block>
                        <xsl:value-of select="lot/csd/csd_line" />
                      </fo:block>
                      <fo:block>
                        <xsl:value-of select="lot/csd/set_description" />
                      </fo:block>
                      <fo:block>
                        <xsl:value-of select="lot/lot_components/component/label" />
                      </fo:block>
                    </fo:block>
                  </fo:table-cell>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
            Line Number:
            <xsl:value-of select="line_number" />
          </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="1pt" border-color="black" padding="2pt" background-repeat="repeat" display-align="center">
          <fo:block text-align="center">
            <fo:block>
              <xsl:value-of select="product/unit_of_measure" />
            </fo:block>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="1pt" border-color="black" padding="2pt" background-repeat="repeat" display-align="center">
          <fo:block text-align="center">
            <fo:block>
              <xsl:value-of select="stock_charges/storage_rate" />
            </fo:block>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="1pt" border-color="black" padding="2pt" background-repeat="repeat" display-align="center">
          <fo:block text-align="center">
            <fo:block>
              <xsl:value-of select="stock_charges/storage_amount" />
            </fo:block>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="1pt" border-color="black" padding="2pt" background-repeat="repeat" display-align="center">
          <fo:block text-align="center">
            <fo:block>
              <xsl:value-of select="stock_charges/handling_rate" />
            </fo:block>
          </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="1pt" border-color="black" padding="2pt" background-repeat="repeat" display-align="center">
          <fo:block text-align="center">
            <fo:block>
              <xsl:value-of select="stock_charges/handling_amount" />
            </fo:block>
          </fo:block>
        </fo:table-cell>
      </fo:table-row>
    </xsl:for-each>
  </fo:table-body>
</fo:table>
修订

:

所以我决定使用页脚来显示每个页面上的小计,并在我的表中设置了一个标记,简单地返回总只是为了测试它,但现在我认为的是,我可以尝试以某种方式在我的xml文件中获取节点的位置,并使用类似的东西…

<xsl:value-of select="sum(preceding::value[the_position]"/> 

value实际上是电荷总数的名称,这是可行的吗?如果一直在尝试不同的东西,但我不确定的语法和如何返回的位置。

为完整起见,将解决方案的描述作为答案发布。

如果你的行是相当规则的高度,你可以使用sum()函数在所有以前的节点在你的表结构中输出行,并把运行的小计作为一个表/表行在页脚的标记作为单行表。使用页面上的最后一个页脚将标记检索到页脚中(不是带有Retrieve -table-marker的表脚),然后清除标记。仔细调整大小,你可以让它看起来就像一个表脚,你可以清除在表末尾的标记,这样它就不会出现在其他页面上。对于表端,只输出总数。

它可能不适用于复杂的表,特别是当有多行并且保持在这些行上时,因为表可能无法到达页脚。

这克服了两个问题(1)您不需要表标记,因为许多FO引擎不支持它们(实际上有很好的理由,因为如果正在检索的内容可能具有较大的可变高度,它们比您想象的更有问题)。(2)使用表标记可能会在页脚内的表末尾遇到问题,您可能不想要它(尽管您可以清除最后一行的标记)。

相关内容

最新更新