1

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

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Petruza
  • 11,744
  • 25
  • 84
  • 136

1 Answers1

1

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

kjhughes
  • 106,133
  • 27
  • 181
  • 240