Get a string sequence from a node-set in XPath 1.0
I'm using XPath 1.0 to parse an HTML file and I want to get a string sequence from a node-set. First I select a node-set (eg: //div
) and then I want the string-value of each node of the set. I've tried with string(//div)
but it only returns the string-value of the first node in the set.
Example开发者_如何学Go:
<foo>
<div>
bbbb<p>aaa</p>
</div>
<div>
cccc<p>aaa</p>
</div>
</foo>
I expect a result like ('bbbbaaa', 'ccccaaa')
but I only get 'bbbaaa'
In XPath 1.0 the "string-value of a node-set" is by definition the string value of the first node in the node-set.
In XPath 2.0 the following expression produces a sequence of the string values of all div
elements in an XML document:
//div/string(.)
精彩评论