2012-04-22 40 views
1

我创建一个XSL象下面这样:如何在xsl中使用变量?

<xsl:choose> 
    <xsl:when test="range_from &lt; 0 and range_to > 5"> 
     <xsl:variable name="markup_03" select="((7 div $total_price_02) * 100)"/> 
    </xsl:when> 
    <xsl:when test="range_from &lt; 6 and range_to > 10"> 
     <xsl:variable name="markup_03" select="((5 div $total_price_02) * 100)"/> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:variable name="markup_03" select="0"/> 
    </xsl:otherwise> 
</xsl:choose> 
<xsl:variable name="total_price_03" select="(($total_price_02 * $markup_03) div 100) + $total_price_02"/> 

我收到以下错误:

A reference to variable or parameter 'markup_03' cannot be resolved. The variable or parameter may not be defined, or it may not be in scope

回答

2

您声明的<xsl:choose>条件内markup_03,所以不在范围内,当你试图在<xsl:choose>之外引用它。

相反,声明你<xsl:variable name="markup_03">和窝<xsl:choose>变量的内部,以确定分配给它什么样的价值:

<xsl:variable name="markup_03"> 
     <xsl:choose> 
      <xsl:when test="range_from &lt; 0 and range_to > 5"> 
       <xsl:value-of select="((7 div $total_price_02) * 100)"/> 
      </xsl:when> 
      <xsl:when test="range_from &lt; 6 and range_to > 10"> 
       <xsl:value-of select="((5 div $total_price_02) * 100)"/> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="0"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:variable> 
    <xsl:variable name="total_price_03" select="(($total_price_02 * $markup_03) div 100) + $total_price_02"/>