2

test当预期的输出应该没有时,这段代码给了我输出..

我的 XSLT 处理器有问题还是..?:

    <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>

顺便说一句,我需要原始 XSLT 1.0的解决方案(没有扩展和类似的东西)。

param是否可以在 XSLT 1.0 中为 a 设置布尔参数?

4

3 回答 3

4

您的参数正在评估为字符串。你应该使用:

    <html>
        <xsl:choose>
            <xsl:when test="$IsTextArea = 'true'">
                test
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$IsTextArea"/>
            </xsl:otherwise>
        </xsl:choose>
    </html>
于 2011-06-09T09:11:38.683 回答
3

xsl:value-of 指令将您提供的任何内容转换为字符串。所以 true() 变为“真”,而 false() 变为“假”。在布尔上下文中使用字符串时,任何非空字符串都变为 true(),而 "" 变为 false()。所以 boolean->string->boolean 转换不会往返。在 XSLT 2.0 中,答案是使用 xsl:sequence 而不是 xsl:value-of; 在 1.0 中,只需使用“yes”和“no”之类的字符串来避免混淆。

于 2011-06-09T11:16:56.683 回答
0

不应该是这样的:

<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>

都觉得你的真假都格格不入了。

于 2011-06-09T09:15:06.170 回答