RE: Grouping by a piece of a date

Subject: RE: Grouping by a piece of a date
From: Jeff Saylor <JSaylor@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Sep 2000 14:02:33 -0400
Steve,

I was closing in on the answer, but you beat me to the punch - saving me
from more hair-pulling trial and error.

Thank you very much for your time and effort in writing a clear, easy to
understand answer with example - I (and I am sure others) greatly appreciate
it.

Cheers,

Jeff



-----Original Message-----
From: Steve Muench [mailto:smuench@xxxxxxxxxxxxx]
Sent: Thursday, September 07, 2000 11:22 AM
To: xsl-list@xxxxxxxxxxxxxxxx
Subject: Re: Grouping by a piece of a date


This should do it. 

Two things were wrong.

(1) My <xsl:key> had a typo. The "using=" attribute needs to be "use="
(2) Since your <xsl:key> of:

   <xsl:key name="foo"
      match="/xml/rs:data/z:row"
      use="substring-before(@dCreated,'T')"/>

    is creating an index over the substring-before'd value,
    then when you go to use the index by using the key()
    function, you need to pass in a substring-before'd value
    that will match, so where you had:

     /xml/rs:data/z:row[generate-id(.)=generate-id(key('foo',.))]

    you need:

    /xml/rs:data/z:row[generate-id(.)=
 
generate-id(key('foo',substring-before(@dCreated,'T')))]">

The working example is below...

| From this XML:
| 
| <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
|    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
|    xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
| 
|    <rs:data>
|       <z:row iID="1" dCreated="1900-01-01T01:00:00"/>
|       <z:row iID="2" dCreated="1900-01-02T01:00:00"/>
|       <z:row iID="3" dCreated="1900-01-02T02:00:00"/>
|       <z:row iID="4" dCreated="1900-01-04T01:00:00"/>
|    </rs:data>
| </xml>
| 
| I am trying to group the elements based on only the date part of the
| dCreated value - resulting in:
|    1900-01-01T01:00:00 - iID1
|    1900-01-02T01:00:00 - iID2, iID3
|    1900-01-04T01:00:00 - iID4

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
   xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
   xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">

   <xsl:output indent="yes"/>

   <xsl:key name="foo"
      match="/xml/rs:data/z:row"
      use="substring-before(@dCreated,'T')"/>

 <xsl:template match="/">
   <RowsByCreatedDate>
     <xsl:for-each
      select="/xml/rs:data/z:row[generate-id(.)=
                                 generate-id(
key('foo',substring-before(@dCreated,'T')))]">
     <Created date="{substring-before(@dCreated,'T')}">
       <xsl:for-each select="key('foo',substring-before(@dCreated,'T'))">
         <xsl:copy-of select="."/>
       </xsl:for-each>
     </Created>
   </xsl:for-each>
   </RowsByCreatedDate>
 </xsl:template>
</xsl:stylesheet>  

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly
http://www.oreilly.com/catalog/orxmlapp/





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread