Andrey Yaskulsky
Andrey Yaskulsky

Reputation: 2526

XPath get all values of specific attribute in the whole document

I'm new to XPath and couldn't find the the way of how can I get all possible values of specific attribute in the whole XML file.

I have a situation that almost every tag in a given file has optional lang attribute and I need to get all possible values of lang attribute from the whole file.

Would appreciate any help, thanks

Upvotes: 1

Views: 496

Answers (1)

Andersson
Andersson

Reputation: 52685

If you want to get all possible lang values you can try

//*/@lang

If you want list of unique values only:

distinct-values(//*/@lang)  # For XPath 2.0

or

//*[not(@lang = preceding::*/@lang)]/@lang  # For XPath 1.0

Upvotes: 3

Related Questions