Search code examples
xsltxslt-2.0

OR condition on value of XML nodes


I need to check the value of XML node. But why is this not working?

 <xsl:if test="(applicationData/remittingAccount/paymentMethodCode != 'ABC' or 
 applicationData/remittingAccount/paymentMethodCode != 'XYZ')">

I have tried this too

 <xsl:if test="(applicationData/remittingAccount/paymentMethodCode != 'ABC') or 
 (applicationData/remittingAccount/paymentMethodCode != 'XYZ')">

and this

 <xsl:if test="applicationData/remittingAccount/paymentMethodCode != 'ABC' or 
 applicationData/remittingAccount/paymentMethodCode != 'XYZ'">

please help!


Solution

  • The test:

    test="node != 'ABC' or node != 'XYZ'"
    

    will returns false only when node does not exist.

    In all other cases the test will always be true, even if there is only one node - because a node's string value cannot be both "ABC" and "XYZ" at the same time, so at least one of the statements will be true.

    You are probably looking for:

    test="not(node = 'ABC' or node = 'XYZ')"
    

    which will be true if there is no node with either of these string values.


    See also: https://en.wikipedia.org/wiki/De_Morgan%27s_laws