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

xml - Extract substrings with XSLT -

math - "ELO Rating" and how does "TSR Rating" work? -

How can do a tuple comparison in coffeescript similar to that in python? -