【问题标题】:xsl checking variable doesn't seem to workxsl 检查变量似乎不起作用
【发布时间】:2009-12-15 16:41:25
【问题描述】:

当我直接输出节点的值例如:

 <fo:inline><xsl:value-of select="isEnabled" /></fo:inline>

我得到了以 pdf "true" 输出的正确字符串..

但是如果我将 isEnabled 的值直接设置为一个变量,然后尝试对其进行比较.. 它似乎不起作用,就好像节点不存在一样。

<xsl:variable name="isEnabled" select="isEnabled" />

<xsl:choose>
<xsl:when test="$isEnabled = 'true'">
   dostuff...

这里好像从来没有正确接收到值,测试总是失败

有什么想法吗?

【问题讨论】:

  • 当你&lt;xsl:value-of select="isEnabled" /&gt; 时发生了什么?
  • 显示文本“true”

标签: xpath xslt pdf-generation apache-fop


【解决方案1】:

isEnabled 是否包含空格?

<isEnabled>true</isEnabled>

对比

<isEnabled>true </isEnabled>

<isEnabled>
true
</isEnabled>

将为您的测试提供不同的结果。第一个应该通过,接下来的两个可能不会。然而,当使用 value-of 时,它们可能都呈现为文本“true”。

【讨论】:

  • 啊,是的,也许我需要忽略空间功能或修剪
【解决方案2】:

怎么样?

<xsl:variable name="isEnabled">
    <xsl:value-of select="isEnabled" />
</xsl:variable>

<xsl:when test="normalize-space($isEnabled)='true'">

【讨论】:

  • 如果我不是真正检查布尔值而是真正检查字符串“true”,这会起作用吗?
  • 针对您针对字符串值进行测试的情况进行了编辑。
【解决方案3】:

好的,原来这不是 xsl 问题,但问题要早得多.. 在为转换生成 xml 的速度模板上。我该如何结束这个问题?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    • 2015-06-06
    相关资源
    最近更新 更多