Re: [xsl] Grouping based on child value

Subject: Re: [xsl] Grouping based on child value
From: "Terry Badger terry_badger@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Jun 2025 19:29:44 -0000
Slight change
B <xsl:template match="root">
B  B  B  B  <xsl:copy>
B  B  B  B  B  B  <xsl:for-each-group group-starting-with="record[col1[. =
'PG']]" select="record">
B  B  B  B  B  B  B  B  <group>
B  B  B  B  B  B  B  B  B  B  <xsl:copy-of select="current-group()"/>
B  B  B  B  B  B  B  B  </group>
B  B  B  B  B  B  </xsl:for-each-group>
B  B  B  B  </xsl:copy>
B  B  </xsl:template>

Terry Badger






On Thursday, June 5, 2025 at 02:56:28 PM EDT, Martin Honnen
martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:









On 05/06/2025 20:49, rick@xxxxxxxxxxxxxx wrote:


>B B 
> Here is my XML:
>
>B B B 
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <root>
>
> B B B  <record>
>
> B B B B B B B  <col1>PG</col1>
>
> B B B  </record>
>
> B B B  <record>
>
> B B B B B B B  <col1>1</col1>
>
> B B B  </record>
>
> B B B  <record>
>
> B B B B B B B  <col1>2</col1>
>
> B B B  </record>
>
> B B B  <record>
>
> B B B B B B B  <col1>PG</col1>
>
> B B B  </record>
>
> B B B  <record>
>
> B B B B B B B  <col1>3</col1>
>
> B B B  </record>
>
> B B B  <record>
>
> B B B B B B B  <col1>4</col1>
>
> B B B  </record>
>
> </root>
>
>B B B 
>
> I want to group all of the <record> elements, starting with
col1[starts-with(.,bPGb)]. I am expecting 2 groups of 3 record elements
each.
>




A variant of your code with e.g.

B B B  <xsl:template match="root">

B B B B B B B  <xsl:copy>


B B B B B B B B B B B  <xsl:for-each-group select="record"
group-starting-with="record[col1[.='PG']]">

B B B B B B B B B B B B B B B  <group></group>

B B B B B B B B B B B  </xsl:for-each-group>

B B B B B B B  </xsl:copy>

B B B  </xsl:template>

would do that. Remember, the group-starting-with is a pattern the element to
start a group has to match.




B B XSL-List info and archive
EasyUnsubscribe (by email)

Current Thread