bslima
bslima

Reputation: 1145

Xpath selecting text() preceding br based on previous sibling text

I have this HTML code:

<td width="220" align="left">
    <b>Valor da Venda:</b> 
    R$ 650.000,00<br>
    <b>Valor do IPTU:</b> 
    R$ 0,00<br>
    <b>Valor do Condomínio:</b> 
    R$ 0,00
</td>

I'm trying to select the text() from preceding "br" tags where the text() in the preceding "b" tag is equal to "Valor da Venda:".

I tried with:

/td//text()[preceding::br and contains(../b/text(),'Valor da Venda:')]

But this is returning

[' R$ 650.000,00', ' R$ 0,00', ' R$ 0,00 ']

while i wanted to return only the first one R$ 650.000,00

Thanks for the help in advance

Upvotes: 2

Views: 3953

Answers (1)

Wrikken
Wrikken

Reputation: 70470

While not exactly as asked, might this be a solution for you?

/td/b[.="Valor da Venda:"]/following-sibling::text()[1]

Or, if the brneeds to be checked:

/td/b[.="Valor da Venda:"]/following-sibling::text()[1][following-sibling::br]'

Upvotes: 2

Related Questions