Conditional AND OR two different meanings

I have an AND and OR concatenation for two 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 run a conditional test or do I need to split it as follows:

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

and in the second element:

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

I searched the Internet but could not find any hints of it. Can someone help me find a solution, please. Thanks and best regards, Peter

+7
source share
1 answer

XPath expression :

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

is syntactically correct .

We cannot say anything about semantics, since an XML document is not provided, and there is no explanation of which expression should choose.

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

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

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

and this can be reorganized into shorter and equivalent:

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

All Articles