What is XPath to find only ONE node (whatever) that has a specific attribute (in fact, this attribute interests me, not node). For example, in my XML, I have several tags that have the lang attribute. I know that they should all have the same value. I just want to get them.
Right now, I am doing this: //*[1][@lang]/@lang , but it seems that it is not working properly for an unknown reason.
My attempts led me to things, ranging from concatenating all @lang values ββ("en en en en ...") to zero, sometimes in between, what I want, but not for all XML.
EDIT:
Actually //@lang[1] cannot work, because the position() function is called before the tag before calling lang . Therefore, it always accepts the very first element found in XML. It worked best at the time, because many times the lang attribute was on the root element.
source share