XPath : finding an attribute node (and only one)

后端 未结 3 771
终归单人心
终归单人心 2021-01-18 21:25

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

3条回答
  •  青春惊慌失措
    2021-01-18 22:30

    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).

提交回复
热议问题