Using XSLT 1.0 (preferably), How can I select all of an element which occurs between the current element and the next time the current element occurs?
Say I have this XML (edited):
<root>
<heading_1>Section 1</heading_1>
<para>...</para>
<list_1>...</list_1>
<heading_2>Section 1.1</heading_2>
<para>...</para>
<heading_3>Section 1.1.1</heading_3>
<para>...</para>
<list_1>...</list_1>
<heading_2>Section 1.2</heading_2>
<para>...</para>
<footnote>...</footnote>
<heading_1>Section 2</heading_1>
<para>...</para>
<list_1>...</list_1>
<heading_2>Section 2.1</heading_2>
<para>...</para>
<list_1>...</list_1>
<list_2>...</list_2>
<heading_3>Seciton 2.1.1</heading_3>
<para>...</para>
<heading_2>Section 2.2</heading_2>
<para>...</para>
<footnote>...</footnote>
</root>
When processing heading_1
I want to select all of heading_2
between the heading I am processing and the next heading_1
. The same for selecting heading_3
when processing heading_2
etc. you get the picture.
You can use this:
Working example:
Result when run on your sample input:
Try the below XPath to select the heading2 when processing heading 1.