My current XPath returns ancestor-or-self nodes matching criteria.
//*[contains(., '"& v_search &"')]/ancestor-or-self::*/*[local-name()='name' and @locale='en']
Now I want to implement addition feature to return following-sibling from the matching nodes. I have changed my XPath as below. But it doesn't return ancestor-or-self plus sibling in result.
//*[contains(., '"& v_search &"')]/ancestor-or-self::*/following-sibling::*/*[local-name()='name' and @locale='en']
here v_search is a variable that can be replaced by any string for testing. My xml is like :-
<root xmlns="https://jlkjsdlfjl/">
<name>Accounts</name>
<property name="included" type="hidden">true</property>
<locales>
<locale>en</locale>
<locale>de</locale>
</locales>
<defaultLocale>en</defaultLocale>
<searchspace>
<name locale="en">Accounts</name>
<name locale="de">Accounts</name>
<lastChanged>2014-03-05T18:47:30</lastChanged>
<lastChangedBy>userx</lastChangedBy>
<property name="included" type="hidden">true</property>
<searchspace>
<name locale="en">Database L</name>
<name locale="zw">Database L</name>
<searchSubject status="valid">
<name locale="en">SName1</name>
<name locale="zw">qskxyz</name>
<searchItem>
<name locale="en">IName1</name>
<name locale="zw">qixyz</name>
<hello>v_search</hello>
</searchItem>
<searchItem>
<name locale="en">IName2</name>
<name locale="zw">abc</name>
v_search
</searchItem>
<searchItem>
<name locale="en">IName3</name>
<name locale="zw">def</name>
<hello>something else</hello>
</searchItem>
</searchSubject>
</searchspace>
</searchspace>
<searchspace>
<name locale="en">Names</name>
<lastChanged>2016-01-12T12:42:46</lastChanged>
<searchspace>
<name locale="en">Database Layer</name>
<name locale="zw">Database Layer</name>
<searchSubject status="valid">
<name locale="en">SName2</name>
<searchItem>
<name locale="en">IName4</name>
<hello>...Hi there..</hello>
</searchItem>
</searchSubject>
</searchspace>
</searchspace>
</root>
v_search is sample keyword, I want to return sibling of lowest matching nodes.
i.e. sibling of self from ancestor-or-self.
following-siblingof which element that you mean;following-siblingof matching element orfollowing-siblingof ancestor of matching element? - har07<hello>v_search</hello>) in the given scenario doesn't have anyfollowing-sibling. So, what element(s) do you actually mean byfollowing-siblingof thev_searchelement here? - har07v_searchand it also has a sibling following it IName3. So the result should beancestor-or-self of IName2and sibling of IName2 that is IName3. - Kailash Singh