【发布时间】:2017-07-13 20:53:45
【问题描述】:
我有这个 XML 和 XSL 示例:
XML:
<mastercount>
<sourceval>
<attm>50</attm>
<fh>6500</fh>
<id>1</id>
</sourceval>
<sourceval>
<attm>15</attm>
<fh>2300</fh>
<id>2</id>
</sourceval>
<sourceval>
<attm>4</attm>
<fh>280</fh>
<id>3</id>
</sourceval>
<sourceval>
<attm>20</attm>
<fh>2700</fh>
<id>4</id>
</sourceval>
</mastercount>
XSL:
<xsl:variable name="var_idx">
<xsl:value-of select="position()" />
</xsl:variable>
<xsl:variable name="var_sum_attm" />
<xsl:variable name="var_sum_fh" />
<fo:table-row>
<xsl:for-each select="/mastercount">
<fo:table-cell padding="3pt" border-style="solid" width="12mm" border-width="1pt" text-align="right">
<fo:block>
<xsl:value-of select="sourceval[position()=$var_idx]/attm" />
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt" border-style="solid" width="12mm" border-width="1pt" text-align="right">
<fo:block>
<xsl:value-of select="sourceval[position()=$var_idx]/fh" />
</fo:block>
</fo:table-cell>
</xsl:for-each>
</fo:table-row>
这部分源代码效果很好,我明白了
attm fh attm fh
Val2 50 6500 0 6500
Val1 15 2300 0 2300
Val3 280 0 280 0
Val4 20 2700 0 2700
(我在源代码中跳过了上面的名称部分)
但是我现在需要这两个字段的总和:
attm fh attm fh
Val2 50 6500 0 6500
Val1 15 2300 0 2300
Val3 280 0 280 0
Val4 20 2700 0 2700
sum sum sum sum
我怎样才能让它工作?
有什么想法吗?
感谢您的帮助。 流浪汉
更新:
感谢 RT72,这是一个答案:
<xsl:for-each select="/mastercount">
<fo:table-cell padding="3pt" border-style="solid" width="12mm" border-width="1pt" text-align="right">
<fo:block>
<xsl:value-of select="sum(sourceval/attm)"/>
</fo:block>
</fo:table-cell>
<fo:table-cell padding="3pt" border-style="solid" width="12mm" border-width="1pt" text-align="right">
<fo:block>
<xsl:value-of select="sum(sourceval/fh)" />
</fo:block>
</fo:table-cell>
</xsl:for-each>
【问题讨论】:
标签: xml pdf xslt xsl-fo apache-fop