Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional AND OR two different values

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'>
like image 598
Peter Avatar asked Mar 28 '11 12:03

Peter


1 Answers

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')
like image 176
Dimitre Novatchev Avatar answered Sep 24 '22 14:09

Dimitre Novatchev