开发者

xslt cannot assign a param with a boolean value within `<xsl:choose>`

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()"/>开发者_如何学JAVA
        </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?


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>


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜