1

我正在尝试计算 for 循环中的记录数及其值的总和(对于特定列)。请找到以下代码并建议我。

<xsl:for-each-group select="current-group()" group-by="CostCentre/PCCode">
                 <!-- variables for each pc code -->
                 <xsl:variable name="chargeRate" select="SpaceTariffGroup/ChargeRate"/>
                 <xsl:variable name="dedicatedArea"
                    select="sum((current-group()[SpaceType/ChargeBackType = $chargeBackTypeDedicatedArea]/(Area*CalculationFactor)))"/>            

                 <xsl:variable name="floorFactor"
                    select="$dedicatedArea div ($totalDedicatedAreaPerFloor )"/>`enter code here`
                 <xsl:variable name="floorCommonArea"
                    select="$floorFactor * $totalFloorCommonAreaPerFloor"/>
                 <xsl:variable name="dedicatedAndFloorCommonArea"
                    select="($dedicatedArea + $floorCommonArea)"/>                     

                 <xsl:variable name="totalChargedArea"
                    select="$dedicatedAndFloorCommonArea"/>
                 <xsl:variable name="totalChargedAmount"
                    select="$chargeRate * $totalChargedArea"/>
 <xsl:value-of select="$totalChargedArea"/>
 <xsl:text>,</xsl:text>   
 <xsl:value-of select="$totalChargedAmount"/>
enter code here
</xsl:for-each-group>

会打印这样的东西。100,5000 200,5000 300,5000 400,5000

我想要这样的输出。100,5000 200,5000 300,5000 400,5000 4,20000 (最后一行是总记录,这些记录的值的总和)不知道我怎样才能得到它

4

1 回答 1

2

那么你可以将每个组的结果存储在一个变量中,例如

<xsl:variable name="charges">
<xsl:for-each-group select="current-group()" group-by="CostCentre/PCCode">
                 <!-- variables for each pc code -->
                 <xsl:variable name="chargeRate" select="SpaceTariffGroup/ChargeRate"/>
                 <xsl:variable name="dedicatedArea"
                    select="sum((current-group()[SpaceType/ChargeBackType = $chargeBackTypeDedicatedArea]/(Area*CalculationFactor)))"/>            

                 <xsl:variable name="floorFactor"
                    select="$dedicatedArea div ($totalDedicatedAreaPerFloor )"/>`enter code here`
                 <xsl:variable name="floorCommonArea"
                    select="$floorFactor * $totalFloorCommonAreaPerFloor"/>
                 <xsl:variable name="dedicatedAndFloorCommonArea"
                    select="($dedicatedArea + $floorCommonArea)"/>                     

                 <xsl:variable name="totalChargedArea"
                    select="$dedicatedAndFloorCommonArea"/>
                 <xsl:variable name="totalChargedAmount"
                    select="$chargeRate * $totalChargedArea"/>
 <charge>
    <area><xsl:value-of select="$totalChargedArea"/></area>
    <amount><xsl:value-of select="$totalChargedAmount"/></amount>
  </charge>
</xsl:for-each-group>
</xsl:variable>

然后您可以使用例如处理变量

<xsl:for-each select="$charges/charge">
  <xsl:value-of select="concat(area, ',', amount)"/>
</xsl:for-each>

并输出总和

<xsl:value-of select="sum($charges/charge/amount)"/>
于 2013-03-04T18:29:32.710 回答