2016-06-28 126 views
0

以下是我的代碼。基本上,問題是我需要能夠檢查一個節點,如果它是空的,將它設置爲0,但如果它有一個值,則將其設置爲該值。之後我需要對它進行數學運算(減去數值)。下面是我嘗試過的,但是我收到一個錯誤:「變量參數'quantAvail'要麼沒有定義,要麼超出了範圍。」我不知道如何解決這個問題?檢查節點是否爲空,如果爲空值設爲

<xsl:choose> 
       <xsl:when test="quantitybackordered=''"> 
        <xsl:variable name="quantBackOrdered" select="0"/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:variable name="quantBackOrdered" select="quantitybackordered"/> 
       </xsl:otherwise> 
      </xsl:choose> 

      <xsl:choose> 
       <xsl:when test="locationquantityavailable=''"> 
        <xsl:variable name="quantAvail" select="0"/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:variable name="quantAvail" select="locationquantityavailable"/> 
       </xsl:otherwise> 
      </xsl:choose> 

      <xsl:choose> 
       <xsl:when test="inventoryLocation_internalid='18'"> 
        <xsl:variable name="quantTotal" select="$quantAvail - $quantBackOrdered"/> <!-- Error on this line --> 
        <xsl:value-of select="$quantTotal"/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:variable name="test" select="locationquantityavailable"/> 
        <xsl:choose> 
         <xsl:when test="$test=''"> 
          <xsl:text>0</xsl:text> 
         </xsl:when> 
         <xsl:otherwise> 
          <xsl:value-of select="locationquantityavailable"/> 
         </xsl:otherwise> 
        </xsl:choose> 
       </xsl:otherwise> 
      </xsl:choose> 
+0

的http:// stackoverflow.com/help/someone-answers –

回答

-1

這很難不看上下文(輸入和樣式表的其餘部分)進行通知,但我相信你可以在你的問題重寫部分:

<xsl:variable name="quantBackOrdered"> 
    <xsl:choose> 
     <xsl:when test="quantitybackordered=''">0</xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="quantitybackordered" /> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:variable> 

<xsl:variable name="quantAvail"> 
    <xsl:choose> 
     <xsl:when test="locationquantityavailable=''">0</xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="locationquantityavailable" /> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:variable> 

<xsl:choose> 
    <xsl:when test="inventoryLocation_internalid='18'"> 
     <xsl:value-of select="$quantAvail - $quantBackOrdered"/> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="$quantAvail"/> 
    </xsl:otherwise> 
</xsl:choose>