Xpath: select node based in a condition (with local-name())

87,429

Solution 1

You probably meant

//*[local-name()='a'][*[local-name()='aCode']='aaa']

Solution 2

Try this

/a/aCode[text()='aaa']

or

//*[local-name() = 'aCode' and text() = 'aaa']

You have used // at wrong place.

Solution 3

This one work:

//*[local-name()='a'][*[local-name()='acode' and text()='a2']]

and also this one:

//*[local-name()='a'][aCode[text()='a2']]
Share:
87,429
gisly
Author by

gisly

Updated on July 02, 2020

Comments

  • gisly
    gisly about 4 years

    The question is quite silly, but I am completely stuck. I want to extract child nodes of a node based on a condition. The XML is as follows:

    <a> 
     <aCode>aaa</aCode>
     <aValue>bbb</aValue>
    </a>
    

    The expression is obvious: //a[aCode='aaa']

    But I can't get how I should change it if it is with namespaces and I've got to use local-name(). I've tested the following and it gives a parsing error:

    /*[local-name()='a'][[local-name()='aCode']='aaa']
    

    Has anyone any idea of what I should do?

  • gisly
    gisly about 12 years
    Thanks! I just wanted to get both children.
  • Arup Rakshit
    Arup Rakshit almost 11 years
    Here what * means - [*[local-name()='aCode']='aaa'] ? Help me to understand please!
  • choroba
    choroba almost 11 years
    * stands for "any element".