Matching a node based on a sibling's value with XPath

前端 未结 3 1671
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 18:29

Having a XML document like this:



  
             


        
相关标签:
3条回答
  • 2020-11-30 18:52

    Found it:

    /records/record/name[../record-type/text() = "A"]
    
    0 讨论(0)
  • 2020-11-30 19:12

    Surprisingly, none of the answers to date on this old question provide the simplest XPath solution.

    This simple XPath

    /records/record[record-type = "A"]/name
    

    selects

    <name>svn</name>
    <name>blog</name>
    

    as requested.

    0 讨论(0)
  • 2020-11-30 19:15

    You can also filter a parent element by its children :

    /records/record[record-type[text()='A']]/name

    0 讨论(0)
提交回复
热议问题