Miguel
Miguel

Reputation: 11

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:

<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'

Upvotes: 1

Views: 2720

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243579

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

Upvotes: 4

Related Questions