检查节点是否为空,如果为空值设为
问题描述:
以下是我的代码。基本上,问题是我需要能够检查一个节点,如果它是空的,将它设置为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>
答
这很难不看上下文(输入和样式表的其余部分)进行通知,但我相信你可以在你的问题重写部分:
<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>
的http:// *.com/help/someone-answers –