Xml – Xpath Select node until tag

xmlxpathxslt

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]]

Best Answer

Use:

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

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