[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: using xsl:for-each-group, grouping by child nodes?

Subject: RE: using xsl:for-each-group, grouping by child nodes?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 4 Oct 2008 10:32:30 +0100
RE:  using xsl:for-each-group
Of course it's possible, and not really difficult. 

I have to say my instinct would be to start by transforming this into more
XML-like XML, something like

<players>
  <player>
    <name>joe</name>
    <age>2</age>
    <position>fielder</position>
    <state>ny</state>
    <team>mets</team>

because all subsequent processing you do on the data would then be a lot
clearer. (I know the number isn't the player's age, but I have no idea what
it actually is...)

With that it would be

<xsl:template match="players">
  <xsl:for-each-group select="player" group-by="concat(team, state)">
     <xsl:value-of select="current-grouping-key()"/>
     <xsl:for-each-group select="current-group()" group-by="position">
       <...

Now, if you don't want to do the preprocessing, you just substitute
different expressions into the above:

players -> RESULTSET
player -> ROW
team -> COL[5]/DATA
state -> COL[4]/DATA

etc.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Eric Scheid [mailto:eric.scheid@xxxxxxxxxxxxxxx] 
> Sent: 04 October 2008 08:39
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  using xsl:for-each-group, grouping by child nodes?
> 
> 
> I have export data that looks like this:
> 
> <RESULTSET FOUND="6">
>     <ROW MODID="3" RECORDID="1">
>         <COL><DATA>joe</DATA></COL>
>         <COL><DATA>2</DATA></COL>
>         <COL><DATA>pitcher</DATA></COL>
>         <COL><DATA>ny</DATA></COL>
>         <COL><DATA>mets</DATA></COL>
>     </ROW>
>     <ROW MODID="3" RECORDID="2">
>         <COL><DATA>mark</DATA></COL>
>         <COL><DATA>11</DATA></COL>
>         <COL><DATA>outfielder</DATA></COL>
>         <COL><DATA>ny</DATA></COL>
>         <COL><DATA>mets</DATA></COL>
>     </ROW>
>     <ROW MODID="3" RECORDID="3">
>         <COL><DATA>jane</DATA></COL>
>         <COL><DATA>13</DATA></COL>
>         <COL><DATA>outfielder</DATA></COL>
>         <COL><DATA>ny</DATA></COL>
>         <COL><DATA>cubs</DATA></COL>
>     </ROW>
>     <ROW MODID="3" RECORDID="4">
>         <COL><DATA>mike</DATA></COL>
>         <COL><DATA>7</DATA></COL>
>         <COL><DATA>outfielder</DATA></COL>
>         <COL><DATA>ny</DATA></COL>
>         <COL><DATA>mets</DATA></COL>
>     </ROW>
> </RESULTSET>
> 
> I'm trying to transform it into this:
> 
>     Team: mets, ny
>         pitchers:
>             joe, 2
>         oufielders:
>             mark, 11
>             mike, 7
> 
>     Team: cubs, ny
>         outfielders:
>             jane, 13
> 
> .. so naturally I thought of using for-each-group, only 
> problem is I can't find any examples which shows how to 
> group-by using values in the child nodes .. so I don't know 
> if this is even possible, let alone exactly how to specify 
> it. I've tried a few different things to no avail.
> 
> Is this even possible?
> 
> e.
> 
> 
> --
> Ironclad Networks
> Information Architecture
> http://www.ironclad.com.au/
> 
> "Providing tactical IA services to web agencies"

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.