如何使用选择和何时更改变量值

How to change a variable value using choose and when

我正在尝试围绕计算出的变量值建立一些规则,但我正在努力让规则在使用其中一个或两个条件时返回 false 输出的情况下工作。我需要同时使用两个限定条件,但在错误测试过程中单独尝试了每个参数。

我有一个名为 "calculation" 的变量。但是,当对其应用折扣金额时,我不希望计算值低于 301.12。然而,这仅适用于已应用折扣金额的情况。如果计算值低于 301.12 没有折扣那么这没问题,较低的值是可以接受的。

然而,当进程 运行 时,应用折扣后较低的值仍在返回。

非常感谢所有帮助。

这是我的代码:

        <xsl:variable name="discountAmount">
          <xsl:choose>
           <xsl:when test="@affiliateID='12345'">50</xsl:when>
           <xsl:otherwise>0</xsl:otherwise>
          </xsl:choose>
         </xsl:variable>
        <xsl:variable name="feeAmount">
          <xsl:choose>
           <xsl:when test="@affiliateID='12345'">25</xsl:when>
           <xsl:otherwise>50</xsl:otherwise>
          </xsl:choose>
         </xsl:variable>
        <xsl:variable name="grossAmount" select="format-number(db1:grossPremium, '#0.00')" />
        <xsl:variable name="discountGiven" select="($grossAmount - $feeAmount) div 100 * $discountAmount" />
        <xsl:variable name="calculation" select="($grossAmount - $discountGiven)" />
        <xsl:choose>
            <xsl:when test="$discountAmount &gt; 0">
                <xsl:choose>
                     <xsl:when test="$calculation &lt; 301.12"> 
                        <xsl:value-of select="$calculation=301.12" />
                    </xsl:when>
                </xsl:choose>
            </xsl:when>
        </xsl:choose>

您不能更改 XSLT 中变量的值。像这样尝试:

<xsl:variable name="calc0" select="($grossAmount - $discountGiven)" />
<xsl:variable name="calculation">
  <xsl:choose>
    <xsl:when test="$discountAmount &gt; 0 and $calc0 &lt; 301.12">
      301.12
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$calc0" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>