Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath Select node until tag

Tags:

xml

xslt

xpath

How to select all node p until a node div ?

<div>
 <div>blbaba</div>
 <p>a</p>
 <p>b</p>
 <p>c</p>
 <p>d</p>
 <div>blbaba</div>
 <p>e</p>
 <p>f</p>
 <p>g</p>
 <p>h</p> 
 <div>blbaba</div>
</div>

i want a,b,c,d or e,f,g,h i tried something like : //div/following::p[preceding-sibling::div[1]]

like image 916
zedouard Avatar asked Jun 12 '12 08:06

zedouard


1 Answers

Use:

/div/div/following::p[count(preceding::div) = 1]

to get p after 1stdiv and before 2nd. Replace 1 in expression with 2 to select p after 2nddiv and before 3rd.

like image 155
Kirill Polishchuk Avatar answered Nov 15 '22 10:11

Kirill Polishchuk