如何在 XSLT 中检查变量是否为 Null 或为空?

Ole*_*_08 8 xslt xsl-choose

我定义了以下变量:

<xsl:variable name="pica036E"
                        select="recordData/record/datafield[@tag='036E']" />
<xsl:variable name="pica036F"
                        select="recordData/record/datafield[@tag='036F']" />
Run Code Online (Sandbox Code Playgroud)

现在我需要做一个条件,如果变量 pica036E 不为空并且 pica036F 为空,则显示以下消息,否则显示另一条消息。那是我的代码,但我没有任何输出。“空或空”的定义是否正确?

<xsl:choose>
                        <xsl:when test="$pica036E != '' and $pica036F = ''">
                        <xsl:message>
                         036F no 036E yes      
                            </xsl:message>
                        </xsl:when>

                         <xsl:otherwise>
                        <xsl:message>
                                036E no 036F yes
                            </xsl:message>  
                        </xsl:otherwise> 
                    </xsl:choose>  
Run Code Online (Sandbox Code Playgroud)

Mic*_*Kay 9

在 XPath 中,X=Y 表示(如果 X 中的某对 x,Y 中的 y 满足 x = y),而 X != Y 表示(如果 X 中的某对 x,Y 中的 y 满足 x != y)。

这意味着如果 X 或 Y 是空序列,则 X=Y 和 X!=Y 都是假的。

例如,$pica036E != ''测试其中是否存在$pica036E非零长度字符串的值。如果没有值,$pica036E则不存在满足此条件的值。

因此,在 XPath 中使用 != 总是一种代码异味。通常,X != Y您应该编写not(X = Y).