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 June 20th, 2005, 01:37 PM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouping Elements using XSLT

Hi All

I have an XML file like below:

<RailInformation>
    <Node1>Going</Node1>
    <OtherInfo/>
</RailInformation>
<RailInformation>
    <Node2>Going</Node2>
    <OtherInfo/>
</RailInformation>
<RailInformation>
    <Node3>Going</Node3>
    <OtherInfo/>
</RailInformation>


<RailInformation>
    <Node1>Coming</Node1>
    <OtherInfo/>
</RailInformation>
<RailInformation>
    <Node2>Coming</Node2>
    <OtherInfo/>
</RailInformation>
<RailInformation>
    <Node3>Coming</Node3>
    <OtherInfo/>
</RailInformation>

As you can see I have the rail information for coming and going. However, the information is not grouped together. I want that all the "Coming" information should be grouped in one group and all the "Going" information should be grouped in another group like the one presented below:

<AllInfoGoing>
    <Node1>Going</Node1>
    <OtherInfo/>
    <Node2>Going</Node2>
    <OtherInfo/>
    <Node3>Going</Node3>
    <OtherInfo/>
</AllInfoGoing>

<AllInfoComing>
    <Node1>Coming</Node1>
    <OtherInfo/>
    <Node2>Coming</Node2>
    <OtherInfo/>
    <Node3>Coming</Node3>
    <OtherInfo/>
</AllInfoComing>

I need to do this using XSTL. I would greatly appreciate any help provided.

Thanks & Regards,
- Anuj Mathur

 
Old June 21st, 2005, 02:08 AM
Authorized User
 
Join Date: May 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to meetnaveen4u
Default

Hi Anuj,
 First thing is, the xml element eg. <node1>, <node2>.... cant be grouped as there is different names. if i have common name like <node>Going</node> <node>Coming</node> would be a easy task for grouping.
U can use this url for further information(http://www.dpawson.co.uk/xsl/sect2/N4852.html). if u can give me exact xml i will help u out. My mail id [email protected].


Thanks &amp; Regards
Naveen.
 
Old June 21st, 2005, 02:56 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>First thing is, the xml element eg. <node1>, <node2>.... cant be grouped as there is different names.

This isn't true. Muenchian grouping (http://www.jenitennison.com/xslt/grouping) allows grouping on any computed value, e.g. translate(name(), '0123456789', ,,).

However, I don't think this is a true grouping problem because the list of possible values is known statically. In fact, it's a very straightforward problem, and the only reason I didn't attempt to respond is that I can't see where the difficulty lies. It's something like this:

<AllInfoGoing>
  <xsl:for-each select="RailInformation[*[1]='Going']">
    <xsl:copy-of select="*"/>
  </xsl:for-each>
</AllInfoGoing>

<AllInfoComing>
  <xsl:for-each select="RailInformation[*[1]='Coming']">
    <xsl:copy-of select="*"/>
  </xsl:for-each>
</AllInfoComing>

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
XSLT Grouping vernc XSLT 2 October 2nd, 2007 03:59 AM
XSLT - Grouping by Attribute but same elements vinaura XSLT 2 July 18th, 2007 10:34 PM
Replacing elements name while grouping. ROCXY XSLT 3 January 6th, 2006 01:11 PM
Grouping orphan nodes to paranet elements ROCXY XSLT 2 January 1st, 2006 07:11 AM
XSLT Grouping Help Missy XSLT 0 December 14th, 2005 10:28 PM





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