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

nested grouping

Subject: nested grouping
From: "Laura Jenkins" <xsl_list@xxxxxxxxxxx>
Date: Thu, 3 Apr 2003 14:56:08 +0100
film adult
Dear All,
I have a problem with grouping. I name it double grouping as I cant get a
better name gor it.
Here it goes. I have an XML which looks like

<?xml version="1.0"?>
<films>
 <slot id = "1">
  <date>day1</date>
  <film id = "horror">Horror-Movie1</film>
 </slot>
 <slot id = "2">
  <date>day1</date>
  <film id = "horror">Horror-Movie2</film>
 </slot>
 <slot id = "3">
  <date>day1</date>
  <film id = "adult">Adult-Movie1</film>
 </slot>
 <slot id = "4">
  <date>day1</date>
  <film id = "adult">Adult-Movie2</film>
 </slot>
 <slot id = "5">
  <date>day2</date>
  <film id = "horror">Horror-Movie3</film>
 </slot>
 <slot id = "6">
  <date>day2</date>
  <film id = "horror">Horror-Movie4</film>
 </slot>
 <slot id = "7">
  <date>day2</date>
  <film id = "adult">Adult-Movie3</film>
 </slot>
 <slot id = "8">
  <date>day2</date>
  <film id = "adult">Adult-Movie4</film>
 </slot>
</films>
and i want to group based on date and within that based on film ids..

In other words, I want the output (HTML) to look like:

Date ** day1
  Horror Movies
    Film Type : horror ** Film :Horror-Movie1
    Film Type : horror ** Film :Horror-Movie2
  Adult Movies
    Film Type : adult ** Film :Adult-Movie1
    Film Type : adult ** Film :Adult-Movie2
Date ** day2

Horror Movies
    Film Type : horror ** Film :Horror-Movie3
    Film Type : horror ** Film :Horror-Movie4
Adult Movies
    Film Type : adult ** Film :Adult-Movie3
    Film Type : adult ** Film :Adult-Movie4


I wrote an xsl that would go as far as grouping based on the dates..to
produce an output that looks like..

Date ** day1
Film Type : horror ** Film :Horror-Movie1
Film Type : horror ** Film :Horror-Movie2
Film Type : adult ** Film :Adult-Movie1
Film Type : adult ** Film :Adult-Movie2
Date ** day2
Film Type : horror ** Film :Horror-Movie1
Film Type : horror ** Film :Horror-Movie1
Film Type : adult ** Film :Adult-Movie1
Film Type : adult ** Film :Adult-Movie2

I cant get my heads around doing what I want. I tried many weird combination
using the keys but couldnt get what I wanted The xsl i wrote is as follows..

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:key match="/films/slot" name="unigue-days" use="date/text()"/>
 <xsl:template match="/">
  <xsl:for-each select="/films/slot[generate-id(.) =
generate-id(key('unique-days',date/text())[1])]">
   <u><b> Date ** <xsl:value-of select="date"/></b></u>
   <br/>
   <xsl:for-each select="key('unique-days',date/text())">
     Film Type : <b> <xsl:value-of select="film/@id"/></b> **
    Film :<b><xsl:value-of select="film"/></b>

    <br/>
   </xsl:for-each>
   <hr/>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>.


It would be of great help if someone could suggest me some way of grouping
elements in the way I wanted.
Cheers.

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


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.