【问题标题】:Easiest way to find the sum of the values in a table in XSL FO在 XSL FO 中查找表中值总和的最简单方法
【发布时间】:2014-12-29 06:16:27
【问题描述】:

我想对表格中的数字列求和,但我无法理解如何在 XSL FO 中做到这一点?谁能简单解释一下
这是我的 XML 输入代码:

<Studies>
<Study>
<name>name1</name>
<amount>500</amount>
<age>5</age>
</Study>
<Study>
<name>name1</name>
<amount>500</amount>
<age>15</age>
</Study>
<Study>
<name>name1</name>
<amount>500</amount>
<age>20</age>
</Study>
</studies>

我希望输出为 Total:1500(即总和) 另请参阅此相关问题:How can I sum up some values per page in a table in XSL-FO?

【问题讨论】:

    标签: xslt xsl-fo


    【解决方案1】:

    您不会“对表格中的数字列求和”;您将进入该列的数字相加。例如:

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
    
    <xsl:template match="/Studies">
        <table>
            <xsl:for-each select="Study">
                <tr>
                    <td><xsl:value-of select="name"/></td>
                    <td><xsl:value-of select="age"/></td>
                    <td><xsl:value-of select="amount"/></td>
                </tr>
            </xsl:for-each>
                <tr>
                    <td colspan="2">Total Amount</td>
                    <td><xsl:value-of select="sum(Study/amount)"/></td>
                </tr>               
        </table>
    </xsl:template>
    
    </xsl:stylesheet>
    

    注意
    XML 区分大小写:&lt;/studies&gt; not 关闭 &lt;Studies&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      相关资源
      最近更新 更多