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 November 5th, 2006, 09:39 PM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl grouping

Hi,
   I have the below xml document
        <mainele>
     <element1> test1 </element1>
      <element2> test2 </element2>
      <element3> test3 </element3>
        </mainele>
     <mainele>
     <element1> test1 </element1>
      <element2> test2 </element2>
      <element3> test3 </element3>
        </mainele>

  I am trying to group elements with similar data to an html output.
Ie. In above example since all elements in both <mainele> have similar data they should be displayed only as a single row on html.
Presently, my data is showing up as 2 different rows on html page.
How should I do the checks using xsl? Please advise.
Thanks.
 
Old November 6th, 2006, 03:34 AM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Any inputs to above will be appreciated. Wanted to add that I need to display a distinct row for each group
that matches. Please advise.

Thanks

 
Old November 6th, 2006, 05:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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

In XSLT 1.0, use Muenchian grouping, or one of the other techniques discussed at http://www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 6th, 2006, 05:13 AM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
 I was looking at the grouping techniques. I have a doubt though. Will these techniques help in displaying only a distinct row after the grouping. Am not sure how this works. Pls. advise.
Thanks.

 
Old November 6th, 2006, 06:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

All the grouping techniques collect together a set of elements having common values (a "group"). What you do with the group afterwards is up to you. One thing you can do is display the first member of the group and discard the rest: the effect of this is to display only the distinct elements.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 6th, 2006, 12:00 PM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am a bit unclear on generating a single row in html and am quite new to XSLT so can someone show an example using above xml.
Thanks in advance
 
Old November 6th, 2006, 12:06 PM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, in above xml some of the <mailele> may contain another <fields> tag
 <mainele>
     <element1> test1 </element1>
      <element2> test2 </element2>
      <element3> test3 </element3>
      <fields>
          <fld1> </fld1>
      </fields>
   </mainele>

I do not have to include such elements for the grouping.
Please could someone explain as it is urgent.
Thanks

 
Old November 6th, 2006, 12:56 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Please could someone explain as it is urgent.

I'll reply if and when I have time.

I'm happy to spend time teaching people who are prepared to take the time to learn. Telling me it's urgent is a good way to ensure I won't answer, because it means you want me to do the work rather than doing it yourself.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 7th, 2006, 12:02 AM
Authorized User
 
Join Date: Nov 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, Thanks. I understand I wanted a quick way to find out. It was just because if someone knows the method already, he/she could let me know. I was not planning to blindly copy the code. Even a pseudo code would have helped to direct me. Besides, the grouping methods describe a lot in code which I am new to. So the syntax and thereby the understanding was confusing.

Thanks..

 
Old November 7th, 2006, 12:13 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I really can't add much to the Jeni Tennison tutorial on grouping that I referred you to earlier. If there's something specific in it that you don't understand, then please ask. But I can't write a new one just for you.

Grouping is also well covered in most books on XSLT. For beginners, Jeni's book is a good choice.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping in xsl saurabh_inblore XSLT 0 January 12th, 2007 12:37 PM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
Section Grouping (XSL Newbie!) vjlomas XSLT 1 February 4th, 2005 04:00 AM
XSL Grouping and Filtering xrow XSLT 1 October 13th, 2004 11:12 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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