I have a following xml:
text
text
text
te
I think there's a much simpler and probably faster solution: you want all preceding siblings of the second divider that have at least one preceding sibling divider:
/doc/divider[2]/preceding-sibling::p[preceding-sibling::divider]
It gets a bit more complex, of course, if you want to find the paras between the second and third dividers: then you want something more like Daniel Haley's solution.