RE: [xsl] group data in XSL

Subject: RE: [xsl] group data in XSL
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Wed, 18 Aug 2004 16:42:05 +0000
As Andy Suggested, You can do that using XSLT2.0, Make sure your texts are sorted in the reporting unit section.
If you belong to the Microsoft Family, that pronounced non acceptance of XSLT2,
or using XSLT processor that doesnt yet support XSLT 2, then here is a solution using XSLT1.0
It works,
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:key match="/dsWMSRpt/WMSReport" name="report-unit" use="ReportUnitTitle"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select = "/dsWMSRpt/WMSReport[generate-id(.)=generate-id(key('report-unit',ReportUnitTitle)[1])]">
<xsl:variable name = "unit" select = "ReportUnitTitle"/>
<xsl:text>Administration Code: </xsl:text>
<xsl:value-of select = "/dsWMSRpt/WMSReport/AdministrationCode/text()"/>
<xsl:text>&#xa;</xsl:text>
<xsl:text>Report Title: </xsl:text>
<xsl:value-of select = "$unit"/>
<xsl:text>&#xa;</xsl:text>
<xsl:for-each select = "key('report-unit',$unit)">
<xsl:text>Position Number:</xsl:text>
<xsl:value-of select = "PositionNumber/text()"/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Note. Please make sure ur ReportUnit node has values as suggested by Andrew...

HTH
Vasu


From: Tham Tinh <khautinh@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: XSL List <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] group data in XSL
Date: Wed, 18 Aug 2004 07:48:41 -0700 (PDT)

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


=====
"It is essential to know that to be a happy person, a happy family, a happy society, it is very crucial to have a good heart, that is very crucial,"
Dalai Lama




__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail


_________________________________________________________________
Want to block unwanted pop-ups? Download the free MSN Toolbar now! http://toolbar.msn.co.uk/


Current Thread