What is the XPath to find only ONE node (whichever) having a certain attribute (actually I\'m interested in the attribute, not the node). For example, in my XML, I have seve
Did you tried this?
//@lang[1]
here you can see an example.
The following XPath seems to do what you want:
//*[@lang][1]/attribute::lang
After some more tackling, here is a working solution :
(//@lang)[1]
Parentheses are needed to separate the [1]
from the attribute name, otherwise the position()
function is applied within the parent element of the attribute (which is useless since there can be only one attribute of a certain name within a tag : that's why //@lang[2]
always selects nothing).