首页 > 解决方案 > 在 XSLT 中使用 IF 函数来确定字段是否为空白,如果是则添加文本常量

问题描述

目前我正在尝试使用 XSLT 创建一个 IF 样式语句。我希望语句读取如下内容:如果此字段为空白或包含“EMPTY”字样,则输出“NotDetermined”字样。

这是我的 XSLT:

<FirstName>
<--I believe the IF/Test statement should start around here-->
<xsl:value-of select="FirstName"/>
</FirstName>

标签: xmlxslt

解决方案


尝试这个

<xsl:value-of select="if(normalize-space(FirstName) = '' or normalize-space(FirstName) = 'EMPTY') then 'NotDetermined' else FirstName"/>

或这个

        <xsl:choose>
            <xsl:when test="normalize-space(FirstName) = '' or normalize-space(FirstName) = 'EMPTY'"><xsl:text>NotDetermined</xsl:text></xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="FirstName"/>
            </xsl:otherwise>
        </xsl:choose>

推荐阅读