Can XPath match on parts of an element's name?

后端 未结 3 754

I want to do this:

//*fu

which returns all nodes whose name ends in fu, such as

3条回答
  •  死守一世寂寞
    2020-12-28 13:52

    I struggled with Dimitre Novatchev's answer, it wouldn't return matches. I knew your XPath must have a section telling that "fu" has length 2.

    It's advised to have a string-length('fu') to determine what to substring.

    For those who aren't able to get results with his answer and they require solution with xpath 1.0:

    //*[substring(name(), string-length(name()) - string-length('fu') +1) = 'fu']

    Finds matches of elements ending with "fu"

    or

    //*[substring(name(), string-length(name()) - string-length('Position') +1) = 'Position']

    Finds matches to elements ending with "Position"

提交回复
热议问题