XPath operator “!=”. How does it work?

后端 未结 2 904
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 19:29

XML document:


       
        Hello!   
     

         
        
             


        
2条回答
  •  醉话见心
    2020-12-08 20:02

    Recommendation: Never use the != operator to compare inequality where one or both arguments are node-sets.

    By definition the expression:

    $node-set != $value
    

    evaluates to true() exactly when there is at least one node in $node-set such that its string value is not equal to the string value of $value.

    Using this definition:

    $empty-nodeset != $value 
    

    is always false(), because there isn't even a single node in $empty-nodeset for which the inequality holds.

    Solution:

    Use:

    not($node-set = $value)
    

    Then you get all results true(), as wanted.

提交回复
热议问题