XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 26th, 2004, 08:34 AM
Mickah Mickah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 Mickah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 26 sec
Reputation Power: 0
XSL: Accessing previous node element

XML:

Code:
<articles>
	<article>
		<ArticleID>756</ArticleID> 
		<ArticleDate>16/07/2004</ArticleDate> 
		<Expiry>01/01/2012</Expiry> 
	</article>
	<article>
		<ArticleID>755</ArticleID> 
		<ArticleDate>11/06/2003</ArticleDate> 
		<Expiry>01/01/2012</Expiry> 
	</article>
</articles>


XSL:

Code:
<xsl:template match="article">
         <xsl:param name="currentyear" select="substring(ArticleDate, 7, 4)"/> 
		<xsl:choose>
	    	<xsl:when test="position()=1">
			<tr><td><xsl:value-of select="$currentyear"/></td></tr>		
		</xsl:when>
		<xsl:otherwise>
			<xsl:if test="(position()-1)substring(ArticleDate, 7, 3)!=$newyear">
			<tr>
				<td><xsl:value-of select="$newyear"/></td>
				</tr>
	</xsl:if>			
		</xsl:otherwise>
	</xsl:choose>
		<tr><td valign="top"><xsl:apply-templates select="files"/>
		</td></tr>
</xsl:template>


I'm trying to print a list of articles ordered by descending date and grouped by year. So when the year changes from 2004 to 2003, print the year once, list the rest of the 2003 articles and so on (2002,2001).

i.e.

2004
article1
article2
article3
2003
article4
article5
2002
article6


The crux of the problem is this line
Code:
<xsl:if test="(position()-1)substring(ArticleDate, 7, 3)!=$newyear">


I want to access the previous article's date and the year within it and test it against the current year.

Cheers,
Mick

Reply With Quote
  #2  
Old August 26th, 2004, 08:37 AM
Mickah Mickah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 Mickah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 26 sec
Reputation Power: 0
sry, using MSXML2.DOMDocument

Reply With Quote
  #3  
Old August 26th, 2004, 10:15 AM
Mickah Mickah is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 5 Mickah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 26 sec
Reputation Power: 0
Worked it out:

substring(preceding-sibling::article[1]/ArticleDate, 7, 4)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL: Accessing previous node element


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT