Re: [xsl] Including precediing-siblings with the first group

Subject: Re: [xsl] Including precediing-siblings with the first group
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 20 Aug 2022 07:55:50 -0000
Am 18.08.2022 um 16:27 schrieb rick@xxxxxxxxxxxxxx:
>
>
> I have an input file that I want to split into files at each section.
> The first section should include everything before it. Below are my
> input, desired output, and stylesheet. I am pretty sure this is the
> simplest approach, but any suggestions would be appreciated. Thank you.
>
> Rick
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <chapter id="Assault_gd1g1l1027760">
>
> B B B  <title>Transferred Intent</title>
>
> B B B  <toc/>
>
> B B B  <para/>
>
> B B B  <section id="GI_gd1g1o1030579">
>
> B B B B B B B  <title>General Comments</title>
>
> B B B B B B B  <para>General comments here</para>
>
> B B B  </section>
>
> B B B  <section id="GI_gd1g1p1030593">
>
> <title>InstructionbTransferred IntentbDifferent Offense</title>
>
> B B B B B B B  <para>Instructions here</para>
>
> B B B  </section>
>
> B B B  <section id="GI_gd1g1q1030657">
>
> <title>InstructionbTransferred IntentbDifferent Person or
> Propertyo?=</title>
>
> B B B B B B B  <para>More instructions here</para>
>
> B B B  </section>
>
> </chapter>
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <root>
>
> B B  <file>
>
> B B B B B  <title>Transferred Intent</title>
>
> B B B B B  <toc/>
>
> B B B B B  <para/>
>
> B B B B B  <section id="GI_gd1g1o1030579">
>
> B B B B B B B B  <title>General Comments</title>
>
> B B B B B B B B  <para>General comments here</para>
>
> B B B B B  </section>
>
> B B  </file>
>
> B B  <file>
>
> B B B B B  <section id="GI_gd1g1p1030593">
>
> <title>InstructionbTransferred IntentbDifferent Offense</title>
>
> B B B B B B B B  <para>Instructions here</para>
>
> B B B B B  </section>
>
> B B  </file>
>
> B B  <file>
>
> B B B B B  <section id="GI_gd1g1q1030657">
>
> <title>InstructionbTransferred IntentbDifferent Person or
Property</title>
>
> B B B B B B B B  <para>More instructions here</para>
>
> B B B B B  </section>
>
> B B  </file>
>
> </root>
>

It seems, if you want grouping, then for-each-group
group-ending-with="section" is easier:

 B  <xsl:template match="chapter">
 B B B  <root>
 B B B B B  <xsl:for-each-group select="*" group-ending-with="section">
 B B B B B B B  <file>
 B B B B B B B B B  <xsl:apply-templates select="current-group()"/>
 B B B B B B B  </file>
 B B B B B  </xsl:for-each-group>
 B B B  </root>
 B  </xsl:template>

Current Thread