首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSLT变量没有返回任何值

XSLT变量没有返回任何值
EN

Stack Overflow用户
提问于 2019-05-22 21:12:40
回答 1查看 18关注 0票数 0

我声明了2个变量,并用选项填充它们。我想在那之后用if检查它们,但我只得到了两个错误,我不知道它们是从哪里来的。

我尝试更改if语句,但都不起作用。

代码语言:javascript
复制
        <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作为我在我的过程中需要的条件状态...

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-22 21:53:49

变量的作用域是在声明它们的块中,这意味着在您的例子中,它们只存在于xsl:when (和xsl:otherwise)块中,不能在块之外访问。

您可以做的是将xsl:choose放入xsl:variable

代码语言:javascript
复制
<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 ...

代码语言:javascript
复制
<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> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56257678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档