Exclude certain elements from selection in XPath

前端 未结 4 812
悲&欢浪女
悲&欢浪女 2021-01-30 20:51

I know this is a simple question, but I can\'t figure it out. Consider the following simple XML document:


  
  

        
相关标签:
4条回答
  • 2021-01-30 21:31

    Answering to add that in XPath 2.0, you can use except:

    /root/(* except a)
    

    For XPath 1.0, Tomalak pointed out, this is the standard way to do it:

    /root/*[not(self::a)]
    

    By the way, if someone lands here trying to use this in XSLT 2.0 in a xsl:template/@match attribute it won't work because @match takes patterns which although look like XPath expressions, are not XPath expressions. The solution for XPath 1.0 would work in this case.

    0 讨论(0)
  • 2021-01-30 21:44

    I realize this is an old question, but I recently ran into a similar problem and used the following xpath to solve it:

    /root/*[not(name()='a')]
    
    0 讨论(0)
  • 2021-01-30 21:44

    Have you tried:

    /root/b|/root/c|root/d|/root/e

    0 讨论(0)
  • 2021-01-30 21:49
    /root/*[not(self::a)]
    
    0 讨论(0)
提交回复
热议问题