James PiFL Tumber
James PiFL Tumber

Reputation: 33

XPath Get the following-sibling node with local-name due to namespace changing

I've looked through a couple of previous questions about how to select the following sibling but can't seem to do it when I am trying to ignore the namespace to select a following element.

This is an example XML

<root xmlns:foo="http://www.foo.org/">
    <foo:singers>
        <foo:singer>Tom Waits</foo:singer>
        <foo:value>4000</foo:value>
        <foo:singer>B.B. King</foo:singer>
        <foo:value>2000</foo:value>
    </foo:singers>
</root>

I want to get the value following a node based on its value for example the 4000 after Tom Waits.

What I have so far

//*[local-name()='singer' and text() = 'Tom Waits']/following-sibling::*//*[local-name() = 'value']

Unfortunately this isn't working for me.

I can do something like

//*[local-name()='singer' and text() = 'Tom Waits']/following-sibling::foo:value/text()

and that works but I would much prefer to be able to ignore the namespace 'foo'.

Upvotes: 1

Views: 1120

Answers (1)

Nesku
Nesku

Reputation: 501

You were close with what your have so far.
All you need is to replace *//* with * after following-sibling

//*[local-name()='singer' and text() = 'Tom Waits']/following-sibling::*[local-name() = 'value']/text()

Upvotes: 2

Related Questions