This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XSL 2.0 (looking for ideas) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL 2.0 (looking for ideas)" Watch "XSL 2.0 (looking for ideas)" New topic

XSL 2.0 (looking for ideas)

Brian R. Wainwright
Ranch Hand

Joined: Aug 12, 2003
Posts: 92
Hello everyone,

I'm looking for suggestions on how to tackle this problem. I think it can be done using the for-each-group tag in XSLT 2.0. Basically, I've been given an export of FileMaker XML that looks like this:

In case nobody has had to work with FileMaker XML and XSL, it's kind of a pain in the you know what to work with sometimes. I need to transform this FileMaker XML into the following - grouping each value in column 1 together into a single attribute:

I'm thinking of taking the approach of iterating over the first column and gathering the values and the indices and then mixing and matching like that, but the for-each-group element in XSLT may provide what I'm really looking to do quickly and easily. Has anyone used that? Thanks!
Brian R. Wainwright
Ranch Hand

Joined: Aug 12, 2003
Posts: 92
So I've made some progress with this. Progress in sp far as I think I'm on the right track, I just don't quite know what track that is!!! Using the following stylesheet, I think I've managed to group my data by the values in column 1 using <xsl:key>. I then try and iterate over those groupings and get the corresponding values. As far as I can understand, there's one core issue with the stylesheet - the iteration over the group is isn't what I think it is. I think I'm iterating over a single value, which is a string of all the "groupings" (the values from COL[1]/fmpATA) rather than some sort of array-like structure of each group name. Anyway, here's the stylsheet...

And here's the result:

This is promising, but not the result I'm looking for (see previous post). I kind of pulled this strategy together from some research on the web so I'm not quite sure what I'm doing. If anyone can shed some light I'd appreciate it!! Thanks!!!1
[ June 26, 2007: Message edited by: Brian R. Wainwright ]
Brian R. Wainwright
Ranch Hand

Joined: Aug 12, 2003
Posts: 92
Well I finally got this resolved so I'm posting the solution to anyone who may need to do something similar in the future. Basically I used XSL 2.0's for-each-group functionality to get distinct values of my first column. Then I iterate over those groups, and with a nested loop, iterate over ALL the values in that first column, grab the index I'm at and then grab the corresponding values in the other columns based on that index. Voila!

It is sorta covered in the JavaRanch Style Guide.
subject: XSL 2.0 (looking for ideas)
Similar Threads
How to use xsl:when
xsl for xml tags with similar name
xsl getNext to sort output
using xsl:for-each tag in xsl file
Enabling / disabling forms (Struts)