条件 AND OR 两个不同的值

发布于 2024-10-27 10:36:19 字数 452 浏览 1 评论 0原文

我有两个不同变量的 AND 和 OR 串联。我尝试了以下方法:

<xsl:if test="$countryCode = '104'
               and 
              (transactionType != 'Allowance'
                or 
               revenueCenter != '1100')">

但这不起作用。是否可以进行条件测试,或者我是否必须像这样拆分它:

<xsl:if test="$countryCode='104'>

在第二个元素中,我这样做:

<xsl:if transactionType!='Allowance' or revenueCenter!='1100'>

I have a concatenation of AND and OR for 2 different variables. And I tried the following:

<xsl:if test="$countryCode = '104'
               and 
              (transactionType != 'Allowance'
                or 
               revenueCenter != '1100')">

But that does not work. Is it possible to do a conditional test or do I have to split it up like this:

<xsl:if test="$countryCode='104'>

and in a second element I do:

<xsl:if transactionType!='Allowance' or revenueCenter!='1100'>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜吻♂芭芘 2024-11-03 10:36:19

XPath 表达式

    $countryCode='104' 
   and  
    (transactionType!='Allowance' or revenueCenter!='1100')

语法正确

我们无法谈论任何有关语义的内容,因为没有提供 XML 文档,也没有解释表达式必须选择什么。

像往常一样,建议不要使用 != 运算符,除非确实必要——当参数之一是节点集(或序列或XPath 2.0 中的节点集)与大多数人的期望相差甚远。

最好使用函数 not(): 而不是 !=

  $countryCode='104' 
 and  
  (not(transactionType='Allowance') or not(revenueCenter='1100'))

并且这可以进一步重构为更短且等效的:

  $countryCode='104' 
 and  
  not(transactionType='Allowance' and revenueCenter='1100')

The XPath expression:

    $countryCode='104' 
   and  
    (transactionType!='Allowance' or revenueCenter!='1100')

is syntactically correct.

We cannot say anything about the semantics, as no XML document is provided and there is no explanation what the expression must select.

As usual, there is the recommendation not to ose the != operator, unless really necessary -- its use when one of the arguments is a node-set (or sequence or node-set in XPath 2.0) is very far from what most people expect.

Instead of != better use the function not():

  $countryCode='104' 
 and  
  (not(transactionType='Allowance') or not(revenueCenter='1100'))

and this can further be refactored to the shorter and equivalent:

  $countryCode='104' 
 and  
  not(transactionType='Allowance' and revenueCenter='1100')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文