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

RE: group data in XSL

Subject: RE: group data in XSL
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Wed, 18 Aug 2004 17:03:17 +0100
k948
> Hi all,
>
> I have the following data and I would like to group
> them please help.
>
> <?xml version="1.0" standalone="yes"?>
> <dsWMSRpt>
> 	<WMSReport>
> 		<AdministrationCode>ABC</AdministrationCode>
> 		<ReportUnitTitle>Financial
> Div/Headquarters</ReportUnitTitle>
> 		<PositionNumber> 0934</PositionNumber>
> 	</WMSReport>
> 	<WMSReport>
> 		<AdministrationCode>ABC</AdministrationCode>
> 		<ReportUnitTitle>Part Div</ReportUnitTitle>
> 		<PositionNumber> 4563</PositionNumber>
> 	</WMSReport>
> 	<WMSReport>
> 		<AdministrationCode>ABC</AdministrationCode>
> 		<ReportUnitTitle>Financial Div</ReportUnitTitle>
> 		<PositionNumber> K948</PositionNumber>
> 	</WMSReport>
> 	<WMSReport>
> 		<AdministrationCode>ABC</AdministrationCode>
> 		<ReportUnitTitle>Human Resource
> Div</ReportUnitTitle>
> 		<PositionNumber> 6453</PositionNumber>
> 	</WMSReport>
> 	<WMSReport>
> 		<AdministrationCode>ABC</AdministrationCode>
> 		<ReportUnitTitle>HumanResource Div</ReportUnitTitle>
> 		<PositionNumber> 9655</PositionNumber>
> 	</WMSReport>
> 	<WMSReport>
> 		<AdministrationCode>ABC</AdministrationCode>
> 		<ReportUnitTitle>Sale Div</ReportUnitTitle>
> 		<PositionNumber> SDWE</PositionNumber>
> 	</WMSReport>
> 	<WMSReport>
> 		<AdministrationCode>ABC</AdministrationCode>
> 		<ReportUnitTitle>Sale Div</ReportUnitTitle>
> 		<PositionNumber> 4577</PositionNumber>
> 	</WMSReport>
> </dsWMSRpt>
>
> Now I would like the output to group as following
>
> Administration Code: ABC
> Report Title: Financial Div
> Position Number: 0934
> Position Number: K948
>
> Administration Code: ABC
> Report Title: Part Div
> Position Number: 4563
>
> Administration Code: ABC
> Report Title: Sale Div
> Position Number: SDWE
> Position Number: 4577
>
> Administration Code: ABC
> Report Title: Human Resource Div
> Position Number: 6453
> Position Number: 9655

In XSLT 2.0 you can use:

    <xsl:for-each-group select="/dsWMSRpt/WMSReport"
group-by="ReportUnitTitle">
        Administration Code: <xsl:value-of select="AdministrationCode"/>
        Report Title:        <xsl:value-of select="ReportUnitTitle"/>
        <xsl:for-each select="current-group()/PositionNumber">
             Position Number:      <xsl:value-of select="."/>
        </xsl:for-each>
    </xsl:for-each-group>

You will have to sort out the whitespace issues, but you get the idea.
It's worth noting that your output doesn't match your input, because
"Financial Div/Headquarters" and "Financial Div" are different, as are
"Human Resource Div" and "HumanResource Div" when you've grouped using
them.

Cheers
andrew

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.