|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: nested grouping ( solved)
Hi all,
I Think I have done it. The following is what I did and it seems to be
working fine.. Please advice
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key match="/films/slot" name="unique-days" use="date/text()"/>
<xsl:key match="/films/slot" name="unique-films" use="film/@id"/>
<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:variable name="dayid" select="date/text()"/>
<xsl:for-each select="/films/slot[generate-id(.) =
generate-id(key('unique-films',film/@id)[1])]">
Film Type :
<b>
<xsl:value-of select="film/@id"/>
</b> **
<br/>
<xsl:for-each select="key('unique-films',film/@id)[date = $dayid]">
<br/>
Film :
<b>
<xsl:value-of select="film"/>
</b>
<br/>
</xsl:for-each>
<br/>
</xsl:for-each>
<hr/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Cheers
----- Original Message -----
From: "Laura Jenkins" <xsl_list@xxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, April 03, 2003 2:56 PM
Subject: nested grouping
> 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
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








