本文介绍了在 XSLT 中检查字符串是否为 null 或为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 XSL 检查值是否为 null 或为空?

How can I check if a value is null or empty with XSL?

例如,如果 categoryName 为空?我在选择结构时使用了.

For example, if categoryName is empty? I'm using a when choosing construct.

例如:

<xsl:choose>
    <xsl:when test="categoryName !=null">
        <xsl:value-of select="categoryName " />
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="other" />
    </xsl:otherwise>
</xsl:choose>

推荐答案

test="categoryName != ''"

编辑:在我看来,这涵盖了对[not] null or empty"的最可能解释.从问题中推断出,包括它的伪代码和我自己早期使用 XSLT 的经验.即,以下 Java 的等价物是什么?":

Edit: This covers the most likely interpretation, in my opinion, of "[not] null or empty" as inferred from the question, including it's pseudo-code and my own early experience with XSLT. I.e., "What is the equivalent of the following Java?":

// Equivalent Java, NOT XSLT
!(categoryName == null || categoryName.equals(""))

有关更多详细信息,例如,清楚地识别空值与空值,请参阅下面约翰维的回答和/或 XSLT 'fiddle' 我改编自那个答案,其中包括 Michael Kay 评论中的选项以及第六个可能的解释.

For more details e.g., distinctly identifying null vs. empty, see johnvey's answer below and/or the XSLT 'fiddle' I've adapted from that answer, which includes the option in Michael Kay's comment as well as the sixth possible interpretation.

这篇关于在 XSLT 中检查字符串是否为 null 或为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:33
查看更多