【问题标题】:How to change <xsl:variable> value如何更改 <xsl:variable> 值
【发布时间】:2011-09-23 22:49:27
【问题描述】:

我无法让它工作...我只是想更改全局定义变量的值:

                    <xsl:variable name="isBusiness"></xsl:variable>
                    <xsl:choose>
                        <xsl:when test="yes this is a business">
                               <xsl:variable name="isBusiness">true</xsl:variable>                        
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:variable name="isBusiness">false</xsl:variable>
                        </xsl:otherwise>
                    </xsl:choose>    

显然代码是无效的,因为已经定义了,但我该如何更改值?

【问题讨论】:

标签: xml xslt


【解决方案1】:

查看此链接:

http://www.dpawson.co.uk/xsl/sect2/N8090.html#d10874e187

基本上,您的代码应如下所示:

<xsl:variable name="x">
   <xsl:choose>
     <xsl:when test="a">z</xsl:when>
     <xsl:when test="b">zz</xsl:when>
     <xsl:otherwise>zzz</xsl:otherwise>
   </xsl:choose>
 </xsl:variable>

【讨论】:

  • 是的,只是示例将值 true 和 false 绑定到 x,所以它在做 x := if (c) then true else false,可以简化为 x := c
  • @MichaelKay:很抱歉复活了一个旧帖子,但我又碰到了这个帖子,看到了你的评论。我想指出,测试标准是针对文本“是的,这是一家企业”,而不是布尔评估。 xslt 表明这不是一个简单的二元评估,而是选择 2 个或 更多 项,其中只有一项对评估很重要。 eval 的结果在 xslt 上获取真/假响应。干杯!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 1970-01-01
  • 2015-04-07
  • 2019-03-10
  • 1970-01-01
  • 2011-10-04
相关资源
最近更新 更多