Re: [xsl] Grouping with siblings

Subject: Re: [xsl] Grouping with siblings
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 16 Feb 2025 00:12:43 -0000
On 16/02/2025 01:00, Liam R. E. Quin liam@xxxxxxxxxxxxxxxx wrote:
> On Sat, 2025-02-15 at 20:49 +0000,rick@xxxxxxxxxxxxxx wrote:
>> Thank you very much Martin. That got me going in the right direction.
> A quick note - in some cases group-by won't work well. An example can


It was group-starting-with in the posted code, both the original and the
suggestion I made (actually the code I spelled out used only
group-starting-with but I also said that the existence of start and end
marker elements kind of asked for the group-starting-with to wrap a
group-ending-with.


> be if the things to be wrapped are part of a longer sequence, so
> there's stuff outside the group but at the ame level.
>
> An approach there can be to use a mode to grab the nodes you want to be
> children of each chapter in the template matching chapter, and to
> ignore those nodes when encountered with apply-templates processing
> later, as the template for chapter handled them:
>
> <xsl:template match="chapter">
>    <chapter> <!--* or xsl:copy *-->
>      <xsl:apply-attributes select="@*" />
>
>      <!--* find the next chapter, if any *-->
>      <xsl:variable name="next" as="element(chapter)?"
>        select="following-sibling::chapter[1]" />
>
What's the point of that if the input has chapter start and end marker
elements like shown in the original post with e.g.


<root>
 B B B  <div type="book" sID="book1">
 B B B B B B B  <chapter sID="chapter1" n="1"/>
 B B B B B B B  <p sID="p1.1" n="1"/>Paragraph 1 text.
 B B B B B B B  <p eID="p1.1"/>
 B B B B B B B  <p sID="p1.2" n="2"/>Paragraph 2 text with
<emphasis>emphasis</emphasis> added.
 B B B B B B B  <p eID="p1.2"/>
 B B B B B B B  <p sID="p1.3" n="3"/>Paragraph 3 text.
 B B B B B B B  <p eID="p1.3"/>
 B B B B B B B  <chapter eID="chapter1" n="1"/>

Current Thread