Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 6th, 2009, 07:37 AM
Registered User
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default group data in table based on a value


I need to split table based on a tag value. Please refer the below code which is the input xml for me
<funcid>Upld002</funcid> <header>Test1</header> <rec>Rec001</rec>
</exception> <exception> <funcid>Upld003</funcid> <header>Test1</header> <rec>Rec001</rec> </exception> <exception> <funcid>Upld003</funcid> <header>Test2</header> <rec>Rec001</rec> </exception>

From the above tags i'm generating table data with 3 columns as defined above.
My requirement is to split table for every <header> value
For the above example, i have to get 2 tables, first with two rows since <header> value is same for two <exception> tags and second with 1 row.
How can i accomplish this grouping? Can anyone help?

Old January 6th, 2009, 08:46 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

In XSLT 2.0, use the xsl:for-each-group instruction.

If you are stuck with XSLT 1.0, use Muenchian Grouping. Look it up in your favourite XSLT textbook or google for it.
Michael Kay
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
mrame (January 7th, 2009)
Old January 7th, 2009, 03:09 AM
Friend of Wrox
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts

Try this:

<xsl:template match="root">

<xsl:for-each-group select="exception" group-by="header">
<xsl:copy-of select="current-group()/rec"></xsl:copy-of>



Similar Threads
Thread Thread Starter Forum Replies Last Post
populating table from a subform based on a query bjcountry Access 1 April 11th, 2008 06:35 AM
sum group values based on cell criteria darkdestroyer Excel VBA 1 January 9th, 2008 09:13 PM
Group by Weeks in a query or table lryckman Access VBA 4 December 4th, 2006 08:55 AM
How to group the relative data together ? al-hijjawi ADO.NET 0 April 19th, 2006 02:53 PM
Sorting based on formula in group footer NixyJ Crystal Reports 0 August 27th, 2004 06:37 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.