user2439099
user2439099

Reputation:

Nesting of xsl:when conditions

I have a query related to xsl choose , inside xsl choose is being used Now i have two xsl:when condition is there like as hsown below

<xsl:choose>
  <xsl:when test=$labcVar=$cde>
    <xsl:when test="$erf=$der">
      <xsl:value-of select="'edr'" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="'fre'" />
    </xsl:otherwise>

please advise is it the correct approach since insise xsl:when ..I have to begain only when first when condition becomes true the only I should go for second xsl:when condition, please advsie it is aloowed or not

Upvotes: 9

Views: 20740

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122414

You can't nest a when directly inside a when, but you can use another choose:

<xsl:choose>
  <xsl:when test=$labcVar=$cde>
    <xsl:choose>
      <xsl:when test="$erf=$der">
        <xsl:value-of select="'edr'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="'fre'" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:when>
</xsl:choose>

Upvotes: 18

Lukas Eder
Lukas Eder

Reputation: 221255

How about using and

<xsl:when test="$labcVar=$cde and $erf=$der">
    <xsl:value-of select="'edr'" />
</xsl:when>
<xsl:otherwise>
    <xsl:value-of select="'fre'" />
</xsl:otherwise>

Upvotes: 2

Related Questions