Переменные XSLT не имеют значений назад - PullRequest
0 голосов
/ 22 мая 2019

Я объявляю 2 переменные и заполняю их выбором.После этого я хочу проверить их с помощью ifs, но я получил только две ошибки и не знаю, откуда они.

Я пытался изменить операторы 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 в качестве состояния состояния, которое мне нужно в моем процессе ...

1 Ответ

0 голосов
/ 22 мая 2019

Переменные находятся в блоке, в котором они объявлены, что означает, что в вашем случае они существуют только в блоках xsl:whenxsl: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> 
...