473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

xsl multiple grouping

2
hello, I have a difficulty achieving the results I need and I hope that someone here can help me

I have an xml like this
Expand|Select|Wrap|Line Numbers
  1. <products>
  2.         <Product>
  3.                 <ID>1</ID>
  4.                 <Brand>brand1</Brand>
  5.                 <Features>
  6.                         <Feature>feature1</Feature>
  7.                         <Feature>feature2</Feature>
  8.                         <Feature>feature3</Feature>
  9.                 </Features>
  10.         </Product>
  11.         <Product>
  12.                 <ID>2</ID>
  13.                 <Brand>brand1</Brand>
  14.                 <Features>
  15.                         <Feature>feature2</Feature>                        
  16.                         <Feature>feature3</Feature>
  17.                 </Features>
  18.         </Product>
  19.         <Product>
  20.                 <ID>3</ID>
  21.                 <Brand>brand2</Brand>
  22.                 <Features>
  23.                         <Feature>feature1</Feature>
  24.                         <Feature>feature2</Feature>                        
  25.                 </Features>
  26.         </Product>
  27. </products>
  28.  
I need to group the products both by brand AND feature. That means that the result should look like this:
Expand|Select|Wrap|Line Numbers
  1. <groups>
  2.         <group>
  3.                 <Brand>1</Brand>
  4.                 <Feature>feature1</feature>
  5.                 <Product>1</Product>
  6.         </group>
  7.         <group>
  8.                 <Brand>1</Brand>
  9.                 <Feature>feature2</Feature>
  10.                 <Product>1</Product>
  11.                 <Product>2</Product>
  12.         </group>
  13.         <group>
  14.                 <Brand>1</Brand>
  15.                 <Feature>feature3</Feature>
  16.                 <Product>1</Product>
  17.                 <Product>2</Product>
  18.         </group>
  19.         <group>
  20.                 <Brand>2</Brand>
  21.                 <Feature>feature1</Feature>
  22.                 <Product>3</Product>                
  23.         </group>
  24.         <group>
  25.                 <Brand>2</Brand>
  26.                 <Feature>feature2</Feature>
  27.                 <Product>3</Product>                
  28.         </group>
  29. </groups>
  30.  
Any help would be very welcome....
Aug 23 '10 #1

✓ answered by jkmyoung

Assuming brand feature is unique, Muenchian grouping:
http://www.jenitennison.com/xslt/gro...muenchian.html
Expand|Select|Wrap|Line Numbers
  1. <xsl:key name="brandfeature" match="feature" use="concat(../../Brand, .)"/>
  2.  
  3. <xsl:for-each select="/products/Product/Features/Feature[count(.|key('brandfeature', concat(../../Brand, .))[1]) = 1]">
  4.     <group>
  5.         <Brand><xsl:value-of select="../../Brand"/></Brand>
  6.         <Feature><xsl:value-of select="."/></Feature>
  7.         <xsl:for-each select="key('brandfeature', concat(../../Brand, .))">
  8.             <Product><xsl:value-of select="../../ID"/></Product>
  9.         </xsl:for-each>
  10.     </group>
  11. </xsl:for-each>
  12.  

2 1827
jkmyoung
2,057 Expert 2GB
Assuming brand feature is unique, Muenchian grouping:
http://www.jenitennison.com/xslt/gro...muenchian.html
Expand|Select|Wrap|Line Numbers
  1. <xsl:key name="brandfeature" match="feature" use="concat(../../Brand, .)"/>
  2.  
  3. <xsl:for-each select="/products/Product/Features/Feature[count(.|key('brandfeature', concat(../../Brand, .))[1]) = 1]">
  4.     <group>
  5.         <Brand><xsl:value-of select="../../Brand"/></Brand>
  6.         <Feature><xsl:value-of select="."/></Feature>
  7.         <xsl:for-each select="key('brandfeature', concat(../../Brand, .))">
  8.             <Product><xsl:value-of select="../../ID"/></Product>
  9.         </xsl:for-each>
  10.     </group>
  11. </xsl:for-each>
  12.  
Aug 25 '10 #2
GMKal
2
That worked, than you very much
Aug 25 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: thefirstwml | last post by:
I am using Visual Studio.NET 2002 Professional and am attempting to create a report on Crystal Reports for .NET. I know that Crystal Reports can group on anything, and when I add multiple...
6
by: cjm | last post by:
I need to group records and assign a setid to the group. I have a table with data that looks like this ColA ColB 94015 01065 94016 01065 94015 01085 94015 01086 33383 00912 32601 00912
2
by: Andreas Håkansson | last post by:
Seeing how my previous post seem to have fallen between the cracks, I thought I would have a second, more direct, go at it. So my question is "Is it possible to group (Muenchian method) over...
0
by: Stephen | last post by:
I have the following xslt and I am trying to use two levels of grouping. I am first grouping on the report category, then on the report type. The problem is I am sure I have to apply some sort of...
3
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
by: Astrat | last post by:
I am trying to hightlight multiple rows in a report design with specific data. For example, I want to hightlight weekends (i.e. Saturday, Sunday) in yellow. I can accomplish this with the...
9
by: JakeTheSnake | last post by:
Hello, I'm new here, but am really impressed with the positive attitude! I was wondering if someone could give me some help or point me in the right direction. I have a query that returns the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.