Using
string(//div[@class='known']/@name)
This creates the string value of the name attribute of the first order in the div element of the document, so the string value of its class attribute is "unknown" .
If //div[@class='known'] selects more than one div element and you need the value of the name attribute for the k-th div selected, use:
string((//div[@class='known'])[$k]/@name)
where $k must be replaced with the required integer, otherwise the variable $k must be in the evaluation context for the XPath expression.
source share