Is it possible to convert this
<boxed-text>
<para role="Box legend">Box 2 Caption</para>
<para role="Box head">Text Text Text</para>
<para role="Box text">Text Text Text.<sup>1</sup></para>
<para role="Box subhead A">Text Text Text</para>
<para role="Box text">Text Text Text.</para>
<para role="Box subhead A">Text Text Text</para>
<para role="Box text">Text Text Text.</para>
<para role="Box subhead B">Text Text Text</para>
<para role="Box text">Text Text Text.</para>
</boxed-text>
into something like this?
<boxed-text>
<caption><para>Box 2 Caption</para></caption>
<para>Text Text Text</para>
<para>Text Text Text.<sup>1</sup></para>
<sec>
<title>Text Text Text</title>
<para>Text Text Text.</para>
</sec>
<sec>
<title>Text Text Text</title>
<para>Text Text Text.</para>
<sec>
<title>Text Text Text</title>
<para>Text Text Text.</para>
</sec>
</sec>
</boxed-text>
However, subheads may not appear, thus,
<boxed-text>
<para role="Box legend">Box 2 Caption</para>
<para role="Box head">Text Text Text</para>
<para role="Box text">Text Text Text.<sup>1</sup></para>
<para role="Box text">Text Text Text.</para>
<para role="Box text">Text Text Text.</para>
<para role="Box text">Text Text Text.</para>
</boxed-text>
should produce
<boxed-text>
<caption><para>Box 2 Caption</para></caption>
<para>Text Text Text</para>
<para>Text Text Text.<sup>1</sup></para>
<para>Text Text Text.</para>
<para>Text Text Text.</para>
<para>Text Text Text.</para>
</boxed-text>
I am having a hard time getting this done with xsl:for-each-group. An answer will be much appreciated. Thanks in advance!
Here is my edited suggestion, incorporating a slight change to make sure we process all
paraelements when there is nothing to group:When applied to the input
with Saxon 9.4 I get the result
When applied to the input
I get the result