xpath - Getting a substring of an attribute is not working -


this html code:

<table id="laptop_detail" class="table">     <tbody>         <tr>             <td style="padding-left:36px" class="ha">&nbsp;camera pixels &nbsp;</td>             <td class="val">8 megapixel camera</td>         </tr>     </tbody> </table> 

how first character "8" in chrome? approach far is:

$x('//*[@id="laptop_detail"]//tr/td[contains(. ,"camera")]/following-sibling::td[1]/text()[substring(. , 0, 2)]') 

don't put function need output of predicate, instead, apply on node:

substring(//*[@id="laptop_detail"]//tr/td[contains(., "camera")]/following-sibling::td[1], 1, 1) 

note in xpath, characters in string numbered 1, not 0.

also, don't need specify text(), substring knows should operate on strings.

btw, want 1 if number of megapixels 10? maybe

substring-before(..., ' ') 

would work better?


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -