Using XPath
or XSLT 1.0, I need to find each node between processing instructions <?start?>
and <?end?>
. The following code:
//node()[preceding-sibling::processing-instruction()[self::processing-instruction('start')]
following-sibling::processing-instruction()[ self::processing-instruction('end')]]`,
works, but naturally, it only selects nodes between the first PI and the last PI. Is there any way how to select only the nodes that are between each start - end pair?
<root>
abc
<?start?>def<Highlighted
bold="yes"><Highlighted italic="yes">ghi</Highlighted></Highlighted>jkl
<?pi?>
<table>
<Caption>stu</Caption>
</table>vw
<?end?>
xy<?start?>
abc <Caption>def</Caption> ghi<?end?> jkl
</root>
Here is an XSLT 2.0 example that uses
for-each-group group-starting-with/group-ending-with
to find and output the nodes between those pairs of processing instructions:Result for your sample is
Using XSLT 1.0 you can compute the intersection of nodes following the
start
pi and preceding theend
pi: