2011-06-08 85 views
2

我有两个变量,名为可编辑显示我们如何根据另一个变量更改变量的值?

如果编辑true,我想显示的值设置为'block'

如果编辑false,我想显示的值设置为'none'

这是我目前:

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

上面的代码不会的display值设置为none

我们如何根据另一个变量更改变量的值?

回答

2

我没有测试这一点,但对我来说,它看起来像这可能是解决这样的范围问题:

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

你不需要'的'得到常量字符串,您可以在测试='$ editable'>块'时写' 2011-06-08 08:03:50

+0

@Christopher Creutzig。顺便说一句,这是好的:''? – Pacerier 2011-06-08 08:26:56

+0

@Christopher Creutzig:是的,我知道;但我想保持它接近最初的例子,在这个例子中,可以轻松地将'block'或'non'与任何xpath函数进行交换。 – 2011-06-08 08:30:07

相关问题