Checking values in previous node in XSLT

abgsc used Ask the Experts™
Hi, we are using xslt version 1.0.
We have an xml file with elements of type [itinerary], see code. All elements are looped thorugh by using for-each, see code. I want to check the date-value on the previous node looped through and check it with current node date-value. The prev_date variable is not working as it is always the date on the first node and not the previous (the value $last_pos seems correct).

How can I get the previous date value?
itinerary id="42607" dayname="Tuesday" date="11/08/2009" start_time="08:30"></itinerary>
<itinerary id="42608" dayname="Tuesday" date="11/08/2009" start_time="09:30"></itinerary>
<itinerary id="42609" dayname="Wednesday" date="12/08/2009" start_time="08:00"></itinerary>
<itinerary id="42610" dayname="Thursday" date="13/08/2009" start_time="08:30"></itinerary>
<itinerary id="42611" dayname="Thursday" date="13/08/2009" start_time="09:30"></itinerary>
<itinerary id="42612" dayname="Friday" date="14/08/2009" start_time="09:30"></itinerary>
<xsl:for-each select="itinerary">		
	<xsl:variable name ="cur_date">
		<xsl:value-of select ="@date"/>
	<xsl:variable name ="last_pos">
		<xsl:value-of select ="position()-1"/>
	<xsl:variable name ="prev_date" select ="../itinerary[$last_pos]/@date"/>
	<xsl:value-of select ="$last_pos"/>	
                     <xsl:value-of select ="$cur_date"/>
	<xsl:value-of select ="$prev_date"/>

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Architect
Top Expert 2006
as long as you don't sort, you can walk back on the preceding-sibling axis
<xsl:variable name ="prev_date" select ="preceding-sibling::itinerary[1]/@date"/>


thx, very qucik reply that solved my problem!


thx for quick reply!
Gertone (Geert Bormans)Information Architect
Top Expert 2006


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial