1

我正在尝试使用嵌套的 if 语句测试一些值,但它似乎不起作用。第一个 when 块工作正常,但是当它遇到 else 并进入 when test=$country 时,它会中断。文本“在何时和国家之外......”工作正常。问题是最后两段没有打印出来。我不确定这是否与我嵌套 when 语句的方式有关,因为我是 XSLT 的新手。

国家是当我将网站的语言环境更改为美国或英国时。

<xsl:choose>
<xsl:when test="target = 'FX'"> <!-- Normal page -->
    <xsl:choose>
        <xsl:when test="$country = 'US'">
            <p>Inside FX US. Country is <xsl:value-of select="$country" /></p>
        </xsl:when>
        <xsl:otherwise>
            <p>Inside FX GB. Country is <xsl:value-of select="$country" /></p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:when>
<xsl:otherwise> <!-- Graph page -->

<p>Outside when and country is <xsl:value-of select="$country" /></p>
    <xsl:when test="$country = 'US'">
        <p>Inside LPBM US. Country is <xsl:value-of select="$country" /></p>
    </xsl:when>
    <xsl:otherwise>
        <p>Inside LPBM GB. Country is <xsl:value-of select="$country" /></p>
    </xsl:otherwise>
    </xsl:otherwise>
</xsl:choose>
4

1 回答 1

1

<xsl:choose>您的最后一个块周围没有打开和关闭块。尝试将它们添加进去,看看是否能得到想要的结果。

您的 XSLT 应如下所示:

<xsl:choose>
<xsl:when test="target = 'FX'"> <!-- Normal page -->
    <xsl:choose>
        <xsl:when test="$country = 'US'">
            <p>Inside FX US. Country is <xsl:value-of select="$country" /></p>
        </xsl:when>
        <xsl:otherwise>
            <p>Inside FX GB. Country is <xsl:value-of select="$country" /></p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:when>
<xsl:otherwise> <!-- Graph page -->

<p>Outside when and country is <xsl:value-of select="$country" /></p>
    <xsl:choose> <!-- Added this line -->
        <xsl:when test="$country = 'US'">
            <p>Inside LPBM US. Country is <xsl:value-of select="$country" /></p>
        </xsl:when>
        <xsl:otherwise>
            <p>Inside LPBM GB. Country is <xsl:value-of select="$country" /></p>
        </xsl:otherwise>
    </xsl:choose> <!-- Added this line -->
    </xsl:otherwise>
</xsl:choose>
于 2013-08-20T14:28:06.760 回答