google chrome - xpath - join/concat child node siblings text -
i searched , found reference accepted answer did not solve issue. have simple html dom is:
<div class="name-hg"> <h2 class="head-name"><a href="http://www.example.com/example.html" title="example title">times have changed</a></h2> <div class="sub-name">10 things did not know time</div> </div> <div class="name-hg"> <h2 class="head-name"><a href="http://www.example.com/example.html" title="example title">a guide mental fitness</a></h2> <div class="sub-name">i fit... mentally is.</div> </div> <div class="name-hg"> <h2 class="head-name"><a href="http://www.example.com/example.html" title="example title">sllippers & boots</a></h2> <div class="sub-name">fashion eccentric</div> </div> <div class="name-hg"> <h2 class="head-name"><a href="http://www.example.com/example.html" title="example title">bic pen era</a></h2> <div class="sub-name">your childhood not have been better</div> </div>
i trying use xpath (a joined string) "head-name" , "sub-name" class' content. xpath expression did not succeed:
$x("string-join((//div[@class='name-hg']/h2[@class='head-name']/a/text(), //div[@class='name-hg']/div[@class='sub-name']/text()),' ')")
the error message getting, while trying in chrome's console, is:
uncaught domexception: failed execute 'evaluate' on 'document': string 'string-join((//div[@class='name-hg']/h2[@class='head-name']/a/text(), //div[@class='name-hg']/div[@class='sub-name']/text()),' ')' not valid xpath expression.(…)
if there expression use (like following sibling), nice.
thanks lot
here answer in xpath 2.0 (string-join() xpath 2.0 function)
normalize-space(string-join(//div[@class='name-hg']//text(), ' '))
it's not possible asked string joining via pure xpath 1.0 - can list nodes without joining (and iterate , join via external code e.g. javascript), may it'll applicable you.
//div[@class='name-hg']//text()
Comments
Post a Comment