Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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?

Reply With Quote
  #2 (permalink)  
Old January 6th, 2009, 08:46 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
mrame (January 7th, 2009)
  #3 (permalink)  
Old January 7th, 2009, 03:09 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2008
Location: Pondicherry, India
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>


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 06:49 PM.

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