我声明了2个变量,并用选项填充它们。我想在那之后用if检查它们,但我只得到了两个错误,我不知道它们是从哪里来的。
我尝试更改if语句,但都不起作用。
<root>
<xsl:choose>
<xsl:when test="Request/Query/Parameter = 'DateiPfad'">
<xsl:variable name="Con1">
2001
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="Con1">
2000
</xsl:variable>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="Request/Query/Parameter = 'DateiName'">
<xsl:variable name="Con2">
2001
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="Con2">
2000
</xsl:variable>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$Con1 == 2001 and $Con2 == 2001">
<xsl:processing-instruction name="ConditionState">
2001
</xsl:processing-instruction>
</xsl:if>
<xsl:if test="$Con1 == 2000 and $Con2 == 2000">
<xsl:processing-instruction name="ConditionState">
2000
</xsl:processing-instruction>
</xsl:if>
</root>我希望IF结果会给我2000或2001作为我在我的过程中需要的条件状态...
发布于 2019-05-22 21:53:49
变量的作用域是在声明它们的块中,这意味着在您的例子中,它们只存在于xsl:when (和xsl:otherwise)块中,不能在块之外访问。
您可以做的是将xsl:choose放入xsl:variable中
<xsl:template match="/">
<root>
<xsl:variable name="Con1">
<xsl:choose>
<xsl:when test="Request/Query/Parameter = 'DateiPfad'">2001</xsl:when>
<xsl:otherwise>2000</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Con2">
<xsl:choose>
<xsl:when test="Request/Query/Parameter = 'DateiName'">2001</xsl:when>
<xsl:otherwise>2000</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$Con1 = 2001 and $Con2 = 2001">
<xsl:processing-instruction name="ConditionState">
2001
</xsl:processing-instruction>
</xsl:if>
<xsl:if test="$Con1 = 2000 and $Con2 = 2000">
<xsl:processing-instruction name="ConditionState">
2000
</xsl:processing-instruction>
</xsl:if>
</root>
</xsl:template> 当然,在您所展示的示例中,您实际上根本不需要xsl:variable ...
<xsl:template match="/">
<root>
<xsl:if test="Request/Query/Parameter = 'DateiPfad' and Request/Query/Parameter = 'DateiName'">
<xsl:processing-instruction name="ConditionState">
2001
</xsl:processing-instruction>
</xsl:if>
<xsl:if test="not(Request/Query/Parameter = 'DateiPfad') and not(Request/Query/Parameter = 'DateiName')">
<xsl:processing-instruction name="ConditionState">
2000
</xsl:processing-instruction>
</xsl:if>
</root>
</xsl:template> https://stackoverflow.com/questions/56257678
复制相似问题