Conditional AND OR two different values
I have a concatenation of AND and OR for 2 different variables. And I tried t开发者_开发技巧he 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'>
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')
精彩评论