Pacerier
Pacerier

Reputation: 89763

How do we change the value of a variable based on another variable?

I have two variables named editable and display.

If the value of editable is true, I want to set the value of display to 'block'.

If the value of editable is false, I want to set the value of display to 'none'.

This is what I have currently:

   <xsl:param name="editable" select="true()"/>
   <xsl:choose>
      <xsl:when test="$editable">
         <xsl:variable name="display" select="'block'"/>
      </xsl:when>
      <xsl:otherwise>
         <xsl:variable name="display" select="'none'"/>
      </xsl:otherwise>
   </xsl:choose>

The code above doesn't set the value of display to none.

How do we change the value of a variable based on another variable?

Upvotes: 2

Views: 1491

Answers (1)

Doc Brown
Doc Brown

Reputation: 20054

I did not test this, but for me it looks like a problem of scope which might be solved this way:

   <xsl:param name="editable" select="true()"/>
   <xsl:variable name="display">
      <xsl:choose>
         <xsl:when test="$editable">
            <xsl:value-of select="'block'"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="'none'"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:variable>

Upvotes: 2

Related Questions