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

RE: XSL distinct group by date

Subject: RE: XSL distinct group by date
From: "Jacoby, Peter R." <PJACOBY@xxxxxxxxxxxx>
Date: Mon, 25 Apr 2005 13:23:55 -0400
xsl distinct
Mindy,

If you want to group your elements by only the year portion of the date, then
you need to change your xsl:key use attribute to only look at the year.
Something like:

<xsl:key name="documents-by-date" match="newsitem" use="substring(date,
string-length(date)-3, 4)" />

Then you would call it with the same
key('document-by-date', '2004')

or in your code
key('documents-by-date', substring(date, string-length(date)-3, 4))

One other piece that you may want to try is grouping more than just newsitem
elements together (I couldn't tell from your original post if this is what
you
are looking for or not).  You can use the union operator | to match on more
than
one named element.  Something like:
<xsl:key name="documents-by-date" match="newsitem  | whitepapers |
pressreleases" use="substring(date, string-length(date)-3, 4)" />

As you said, you could make it (slightly) simpler by storing the year in a
separate element (or attribute), but it's not necessary to get the desired
functionality.

Hope this helps.


-Peter

-----Original Message-----
From: Mindy McCutchan [mailto:karma@xxxxxxxxxxxxxx]
Sent: Monday, April 25, 2005 12:54 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  XSL distinct group by date

Hi,
The grouping tutorial helped a bit, but I'm not sure how to match by just
part of the content. This is the XSL I have so far:

<xsl:key name="documents-by-date" match="newsitem" use="date" />

<xsl:template match="news">
	<xsl:apply-templates
			select="newsitem[generate-id(.) =
generate-id(key('documents-by-date', date)[1])]" />
</xsl:template>

<xsl:template match="newsitem">
	<xsl:value-of select="substring(date, string-length(date)-3, 4)" />
</xsl:template>

I have it so it outputs just the year portion of the date( ex: 5/6/2004),
but with the dates 5/6/2004, 5/7/2004, 4/8/2005, I want only 2004 & 2005 to
show up once.

Do I need to alter my xml to store the year seperately to group by it only?
This is current structure:

<news>
	<newsitem newsid="1">
		<title>news release1</title>
		<date>5/6/2004</date>
		<description></description>
		<fulltext></fulltext>
	</newsitem>
</news>

Thanks! I'm really learning a lot.

Mindy

> >-----Original Message-----
> >Date: Sun, 24 Apr 2005 08:56:55 +0100
> >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> >From: "Michael Kay" <mike@xxxxxxxxxxxx>
> >Subject: RE:  XSL distinct group by date
> >
> >Are you familiar with
> >
> >http://www.jenitennison.com/xslt/grouping
> >
> >which gives the standard XSLT 1.0 approaches to grouping problems?
> >
> >Michael Kay
> >http://www.saxonica.com/

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.