<tr>第 1 个第 2 个第 3 个第 4 个第 5 个第 6 个第 7 个第 8 个</tr><tr><td><img alt="neso" src="http://www.deporteandaluz.com/web/includes/dhtmlx/imgs/csh_winstyle/minus.gif" style="">文件夹 1</td><td><div style="margin-left:20px;display: inline;"></td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">$78</div></td></tr><tr><td><img alt="neso" src="http://www.deporteandaluz.com/web/includes/dhtmlx/imgs/csh_winstyle/minus.gif" style="margin-left:20px;">文件夹 2<td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">$55</div></td></tr><tr><td><img alt="neso" src="http://www.deporteandaluz.com/web/includes/dhtmlx/imgs/csh_winstyle/minus.gif" style="margin-left:40px;">文件夹 3<td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">
</td><td><div style="margin-left:20px;display: inline;">$44</div></td></tr><tr><td><div style="margin-left:60px;display: inline;">Product 1</div></td><td><div style="margin-left:20px;display: inline;">324234</div></td><td><div style="margin-left:20px;display: inline;">3.00</div></td><td><div style="margin-left:20px;display: inline;">Kilo</div></td><td><div style="margin-left:20px;display: inline;">1.00</div></td><td><div style="margin-left:20px;display: inline;">否</div></td><td><div style="margin-left:20px;display: inline;">€ 33.33</div></td><td><div style="margin-left:20px;display: inline;">€ 33.33</div></td></tr><tr><td><div style="margin-left:60px;display: inline;">Product 2</div></td><td><div style="margin-left:20px;display: inline;">4354354</div></td><td><div style="margin-left:20px;display: inline;">1.00</div></td><td><div style="margin-left:20px;display: inline;">Kilo</div></td><td><div style="margin-left:20px;display: inline;">0.50</div></td><td><div style="margin-left:20px;display: inline;">否</div></td><td><div style="margin-left:20px;display: inline;">€2.53</div></td><td><div style="margin-left:20px;display: inline;">€ 1.26</div></td></tr><tr><td><div style="margin-left:40px;display: inline;">产品 3</div></td><td><div style="margin-left:20px;display: inline;">435436</div></td><td><div style="margin-left:20px;display: inline;">10.00</div></td><td><div style="margin-left:20px;display: inline;">Kilo</div></td><td><div style="margin-left:20px;display: inline;">Yes</div></td><td><div style="margin-left:20px;display: inline;">€ 0.36</div></td><td><div style="margin-left:20px;display: inline;">€ 3.60</div></td></tr><tr><td><div style="margin-left:40px;display: inline;">产品 4</div></td><td><div style="margin-left:20px;display: inline;">435435</div></td><td><div style="margin-left:20px;display: inline;">3.28</div></td><td><div style="margin-left:20px;display: inline;">Kilo</div></td><td><div style="margin-left:20px;display: inline;">1.00</div></td><td><div style="margin-left:20px;display: inline;">否</div></td><td><div style="margin-left:20px;display: inline;">€ 17.38</div></td><td><div style="margin-left:20px;display: inline;">€ 17.38</div></td></tr></tbody></html>
解决方案
将以下模板添加到您的样式表中,以便从当前的
<td><div><xsl:call-template name="sum"><xsl:with-param name="currentRow" select=".."/></xsl:call-template></td></xsl:模板><xsl:template name="sum"><xsl:param name="currentRow"/><xsl:param name="sum" select="0"/><xsl:when test="$currentRow//cell[@sum]"><xsl:call-template name="sum"><xsl:with-param name="currentRow"select="($currentRow//row[cell[@sum]])[1]"/><xsl:with-param name="sum"选择=$sum+"数字(翻译($currentRow/cell[@sum],'$',''))"/></xsl:call-template></xsl:when><xsl:否则><xsl:text>$</xsl:text><xsl:value-of select="$sum"/></xsl:否则></xsl:选择></xsl:模板>
The
<?
The XSLt is:
<xsl:stylesheet version="1.0"
I need to calculate the sum by adding nested folder's last cells.FOLDER1 instead of $23 it should have 23+11+44,FOLDER2 should have 11+44 and FOLDER3 just 44 because there aren't nested rows there.
The expected output is:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<table>
<tbody>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
</tr>
<tr>
<td><img alt="neso" src="http://www.deporteandaluz.com/web/includes/dhtmlx/imgs/csh_winstyle/minus.gif" style="">Folder 1</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">$78</div>
</td>
</tr>
<tr>
<td><img alt="neso" src="http://www.deporteandaluz.com/web/includes/dhtmlx/imgs/csh_winstyle/minus.gif" style="margin-left:20px;">Folder 2</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">$55</div>
</td>
</tr>
<tr>
<td><img alt="neso" src="http://www.deporteandaluz.com/web/includes/dhtmlx/imgs/csh_winstyle/minus.gif" style="margin-left:40px;">Folder 3</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">
</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">$44</div>
</td>
</tr>
<tr>
<td>
<div style="margin-left:60px;display: inline;">Product 1</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">324234</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">3.00</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">Kilo</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">1.00</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">No</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 33.33</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 33.33</div>
</td>
</tr>
<tr>
<td>
<div style="margin-left:60px;display: inline;">Product 2</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">4354354</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">1.00</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">Kilo</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">0.50</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">No</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 2.53</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 1.26</div>
</td>
</tr>
<tr>
<td>
<div style="margin-left:40px;display: inline;">Product 3</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">435436</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">10.00</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">Kilo</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">Yes</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 0.36</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 3.60</div>
</td>
</tr>
<tr>
<td>
<div style="margin-left:40px;display: inline;">Product 4</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">435435</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">3.28</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">Kilo</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">1.00</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">No</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 17.38</div>
</td>
<td>
<div style="margin-left:20px;display: inline;">€ 17.38</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
解决方案
Add the following templates to your stylesheet in order to produce the desired result from the current
<xsl:template match="cell[@sum]" priority="1.5">
<td>
<div>
<xsl:call-template name="sum">
<xsl:with-param name="currentRow" select=".." />
</xsl:call-template>
</div>
</td>
</xsl:template>
<xsl:template name="sum">
<xsl:param name="currentRow" />
<xsl:param name="sum" select="0"/>
<xsl:choose>
<xsl:when test="$currentRow//cell[@sum]">
<xsl:call-template name="sum">
<xsl:with-param name="currentRow"
select="($currentRow//row[cell[@sum]])[1]" />
<xsl:with-param name="sum"
select="$sum+
number(
translate(
$currentRow/cell[@sum],
'$',
''))"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>$</xsl:text>
<xsl:value-of select="$sum"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
这篇关于计算和显示嵌套元素的总和 XSLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 04:18