Thanks for the replies. I forgot to mention that the texts
are posited in the eXist database, hence the need for XQuery.
What I've managed to come up with is this.
1 <hit>
2 (: Check if the initial <pb> is the child of another element,
3 and print the name of that element.

4 {
5 let $i1 := //pb[@urn='urn:nbn:se:kb:digark-7886']
6 return
7 if ($i1[parent:

]) then
8 '<p rend="noindent">'
9 else
10 if ($i1[parent::lg]) then
11 '<lg>'
12 else()
13 }
14 (: Print the material between the pagebreaks.

15 {
16 let $i1 := //pb[@urn='urn:nbn:se:kb:digark-7886'],
17 $i2 := //pb[@urn='urn:nbn:se:kb:digark-7887']
18 for $n in //text()
19 where $n >> $i1 and $n << $i2
20 return $n
21 }
22 (: Check if the final <pb> is the child of another element,
23 and print the name of that element.

24 {
25 let $i2 := //pb[@urn='urn:nbn:se:kb:digark-7887']
26 return
27 if ($i2[parent:

]) then
28 '</p>'
29 else
30 if ($i2[parent::lg]) then
31 '</lg>'
32 else()
33 }
34 </hit>
This works fine, except of course for the 'text()' om line 18.
This outputs only the text, not the text and markup, which is what I
want.
Switching 'text()' for 'node()' or 'element()' doesn't give the
desired result either, naturally.
Any suggestions are welcome. Thanks.
--
Patrik Nyman