Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping ITEM by multiple DATES

Status
Not open for further replies.

gaza165

Programmer
Sep 24, 2010
1
0
0
GB
Code:
<item>
  <pubDate>Mon, 15 Feb 10 00:00:00 +0000</pubDate>
  <title><![CDATA[15 Feb 2010 - 10 Oct 2010: Funk, Soul,    Disco, Hiphop]]></title>

   <dc:date>2010-09-25T01:00:00+01:00</dc:date>
   <dc:date>2010-10-02T01:00:00+01:00</dc:date>
   <dc:date>2010-10-09T01:00:00+01:00</dc:date>
</item>

From the code above I want to be able to organise the ITEMS by their multiple dates see below for an example

25th September
Funk, Soul, Disco, Hiphop

02nd October
Funk, Soul, Disco, Hiphop

09th October
Funk, Soul, Disco, Hiphop

How would i go about doing this scenario




 
[0] You do not mention the working environment, in particular, what kind of processing set up the xml document is going to get processed.

[1] Also, the namespace of dc prefix is not shown. (I would suppose in [2] somewhere it is declared in xsl document with prefix coincide with it, and the prefix I use is dc which is not a generic requirement and can be anything syntactically correct.)

[2] Within the realm of xslt, you can do it like this with the template matching item.
[tt]
<xsl:template match="item">
<xsl:variable name="titledata" select="substring-after(title,': ')" />
<xsl:for-each select="dc:date">
<xsl:variable name="date" select="substring-before(.,'T')" />
<xsl:call-template name="cvtdate">
<xsl:with-param name="sdate" select="$date" />
</xsl:call-template>
<xsl:text>&#x0d;&#x0a;</xsl:text>
<xsl:value-of select="$titledata" />
<xsl:if test="position() != last()">
<xsl:text>&#x0d;&#x0a;&#x0d;&#x0a;</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>

<xsl:template name="cvtdate">
<xsl:param name="sdate" />
<xsl:variable name="yyyy" select="substring-before($sdate,'-')" />
<xsl:variable name="rs_yyyy" select="substring-after($sdate,'-')" />
<xsl:variable name="mm" select="substring-before($rs_yyyy,'-')" />
<xsl:variable name="mm_display">
<xsl:choose>
<xsl:when test="$mm = '01'">Jan</xsl:when>
<xsl:when test="$mm = '02'">Feb</xsl:when>
<xsl:when test="$mm = '03'">Mar</xsl:when>
<xsl:when test="$mm = '04'">Apr</xsl:when>
<xsl:when test="$mm = '05'">May</xsl:when>
<xsl:when test="$mm = '06'">Jun</xsl:when>
<xsl:when test="$mm = '07'">Jul</xsl:when>
<xsl:when test="$mm = '08'">Aug</xsl:when>
<xsl:when test="$mm = '09'">Sep</xsl:when>
<xsl:when test="$mm = '10'">Oct</xsl:when>
<xsl:when test="$mm = '11'">Nov</xsl:when>
<xsl:when test="$mm = '12'">Dec</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="dd" select="substring-after($rs_yyyy,'-')" />
<xsl:variable name="dd_display">
<xsl:choose>
<xsl:when test="number($dd) = 1 or number($dd) = 21 or number($dd) = 31">
<xsl:value-of select="concat(number($dd),'st')" />
</xsl:when>
<xsl:when test="number($dd) = 2 or number($dd) = 22">
<xsl:value-of select="concat(number($dd),'nd')" />
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="concat(number($dd),'th')" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="concat($dd_display,' ',$mm_display)" />
</xsl:template>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top