2

this code is giving me the output test when the expected output should be nothing..

Is it something wrong with my XSLT processor or..? :

    <xsl:template match="/">

         <xsl:param name="IsTextArea">
     <xsl:choose>
        <xsl:when test="false()">
           <xsl:value-of select="true()"/>
        </xsl:when>
        <xsl:otherwise>
           <xsl:value-of select="false()"/>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:param>

  <html>

   <xsl:choose>
   <xsl:when test="$IsTextArea">test
   </xsl:when>
   </xsl:choose>


  </html>
    </xsl:template>

Btw i need a solution for raw XSLT 1.0 (no extensions and stuff like that).

Is it possible to set a boolean parameter for a param in XSLT 1.0?

Pacerier
  • 86,231
  • 106
  • 366
  • 634

3 Answers3

4

Your parameter is evaluating to a string. You should use:

    <html>
        <xsl:choose>
            <xsl:when test="$IsTextArea = 'true'">
                test
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$IsTextArea"/>
            </xsl:otherwise>
        </xsl:choose>
    </html>
Emiliano Poggi
  • 24,390
  • 8
  • 55
  • 67
3

The xsl:value-of instruction converts whatever you give it to a string. So true() becomes "true", and false() becomes "false". When you use a string in a boolean context, any non-empty string becomes true(), while "" becomes false(). So boolean->string->boolean conversion doesn't round-trip. In XSLT 2.0 the answer is to use xsl:sequence instead of xsl:value-of; in 1.0, just use strings like "yes" and "no" to avoid confusion.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • 2
    sorry could you elaborate on the `xsl:sequence` part? do you mean that we will set a sequence with 1 item which is a boolean? – Pacerier Jun 09 '11 at 16:36
0

Shouldn't it be like this:

<xsl:param name="IsTextArea">
 <xsl:choose>
    <xsl:when test="false()">
       <xsl:value-of select="false()"/>
    </xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="true()"/>
    </xsl:otherwise>
 </xsl:choose>

Are think your true and false were out of place.

Hasan Fahim
  • 3,875
  • 1
  • 30
  • 51
  • nop they aren't out of place. since the test is `false()` IsTextArea should be `false()` then (see the code in my question). and the check should fail. Yet it succeeded and this is verified since `test` was displayed. – Pacerier Jun 09 '11 at 16:35