Petruza
Petruza

Reputation: 12276

Can you get the string values of a node list from XPath?

The XPath function string() only returns the string value of the first node if it's fed a node list.
I'm using a selector that selects attributes:
//a/@href
This returns an array of href nodes, which you have to map into each node's string values.

Is there a way to do this inside the selector?
E.G. something like //a/@href/string()

Upvotes: 1

Views: 913

Answers (1)

kjhughes
kjhughes

Reputation: 111686

XPath 1.0

You must iterate the node set in the hosting language to convert each to its string value. string() will indeed only take the string value of the first member of any nodeset passed to it.

XPath 2.0

Your requested XPath, //a/@href/string(), would work directly.

See also

Upvotes: 1

Related Questions