[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Grouping based on child value

Subject: Grouping based on child value
From: "rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Jun 2025 18:48:47 -0000
 Grouping based on child value
Hi all,



Here is my XML:



<?xml version="1.0" encoding="UTF-8"?>

<root>

    <record>

        <col1>PG</col1>

    </record>

    <record>

        <col1>1</col1>

    </record>

    <record>

        <col1>2</col1>

    </record>

    <record>

        <col1>PG</col1>

    </record>

    <record>

        <col1>3</col1>

    </record>

    <record>

        <col1>4</col1>

    </record>

</root>



I want to group all of the <record> elements, starting with
col1[starts-with(.,'PG')]. I am expecting 2 groups of 3 record elements
each. Here is my style sheet:



<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:xs="http://www.w3.org/2001/XMLSchema"

    exclude-result-prefixes="xs"

    version="3.0" expand-text="yes">



    <xsl:output indent="yes"/>



    <xsl:template match="root">

        <xsl:copy>

            <xsl:message
select="count(record[col1[starts-with(.,'PG')]])"></xsl:message>

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

                <group></group>

            </xsl:for-each-group>

        </xsl:copy>

    </xsl:template>



</xsl:stylesheet>



However, my result is a single group:



<?xml version="1.0" encoding="UTF-8"?>

<root>

   <group/>

</root>



Any help would be appreciated. Thank you.



Rick Quatro

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.