[xsl] Problems grouping adjacent siblings

Subject: [xsl] Problems grouping adjacent siblings
From: "Huditsch Roman" <Roman.Huditsch@xxxxxxxxxxxxx>
Date: Thu, 30 Jun 2005 08:37:54 +0200
Good morning list,

I would like to group adjacent siblings which share the same local-name
into a container element.

Given this structure

<ax>
  <e></e>
  <r></r>
  <exp>Example</exp>
  <exp>bla bla</exp>
  <exp>jada jada</exp>
  <b></b>
  <e></e>
  <exp>Example 2</exp>
  <exp>bla bla</exp>
  <v></v>
</ax>
<bx>
  <c></c>
  <exp>Example 3</exp>
  <exp>bla bla</exp>
  <b></b>
</bx>

The following output should be produced:

<ax>
  <e></e>
  <r></r>
    <remark>
  	<exp>Example</exp>
  	<exp>bla bla</exp>
  	<exp>jada jada</exp>
    </remark>
  <b></b>
  <e></e>
  <remark>
    <exp>Example 2</exp>
    <exp>bla bla</exp>
  </remark>
  <v></v>
</ax>
<bx>
  <c></c>
  <r></r>
  <remark>
    <exp>Example 3</exp>
    <exp>bla bla</exp>
  </remark>
  <b></b>
</bx>

I thought that this would be the classical use-case for an
<xsl:for-each-group> with @group-adjacent, but I am getting the
strangest results...
I don't even know if it is better to do the grouping in a template
matching
exp[not(preceding-sibling::*[1][local-name()='exp']) or in a template
matching exp's parent
I also tried to find a @group-starting-with solution, since the first
<exp> always starts with the string 'Example'. But with no success
either....
Can you help me with this problem?
Thank you very much for your help!

Wbr,
Roman

Current Thread