本文介绍了XSL if:使用多个测试条件进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[已解决]

感谢@IanRoberts,我不得不在我的节点上使用 normalize-space 函数来检查它们是否为空.

Thanks to @IanRoberts, I had to use the normalize-space function on my nodes to check if they were empty.

<xsl:if test="((node/ABC!='') and (normalize-space(node/DEF)='') and (normalize-space(node/GHI)=''))">
  This worked perfectly fine.
</xsl:if>

[问题]

我正在尝试创建一个 xsl 条件来检查节点的组合是否为空.我已经尝试了以下条件,但它们不起作用,有没有人知道如何让它工作

I am trying to create a xsl condition to check if combinations of node are empty or not. I have tried below conditions but they do not work, does anyone have an idea as to how to get it working

<xsl:if test=" node/ABC!='' and node/DEF='' and node/GHI='' ">
This does not work
</xsl:if>

我也试过

<xsl:when test="((node/ABC!='') and (node/DEF='') and (node/GHI=''))">
This does not work either..
</xsl:when>

也试过了

<xsl:if test="(node/ABC!='')>
<xsl:if test="(node/DEF='')>
<xsl:if test="(node/GHI='')">
Nope not working..
</xsl:if>
</xsl:if>
</xsl:if>

我,然后尝试使用单个 xsl:if 条件,以下是观察结果

I, then tried with single xsl:if conditions, and below is the observation

<xsl:if test="node/ABC!=''>
**This is working fine**
</xsl:if>

但是,如果我尝试搜索空条件,即

However if i try to search for empty condition, i.e

<xsl:if test="node/ABC=''>
**This does not work**
</xsl:if>

此外,如果我尝试使用 ==(双等于),则会出现 xslt 错误.即

Also, if i try with a == (double equal to), then it gives xslt error. i.e

<xsl:if test="node/ABC==''>
***This gives a compilation error***
</xsl:if>

我想了解如何让我的 xsl:if 测试工作以检查多个条件方面的帮助.提前致谢.

:只是在这里更新所有节点都不为空的 if 条件有效,当我尝试检查三个空节点中的任何其他节点时它不起作用.

: Just to update here that the if condition where all the nodes are not empty works, it does not work when i try to check for any other node out of the three nodes that are empty.

例如:

<xsl:if test=" node/ABC!='' and node/DEF!='' and node/GHI!='' ">
This condition works perfectly fine.
</xsl:if>

推荐答案

感谢@IanRoberts,我不得不在我的节点上使用 normalize-space 函数来检查它们是否为空.

Thanks to @IanRoberts, I had to use the normalize-space function on my nodes to check if they were empty.

<xsl:if test="((node/ABC!='') and (normalize-space(node/DEF)='') and (normalize-space(node/GHI)=''))">
  This worked perfectly fine.
</xsl:if>

这篇关于XSL if:使用多个测试条件进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:43