Checking values in previous node in XSLT

abgsc
abgsc used Ask the Experts™
on
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?
<xml-file:
 
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-file:
 
<xsl:for-each select="itinerary">		
	<xsl:variable name ="cur_date">
		<xsl:value-of select ="@date"/>
	</xsl:variable>					
	<xsl:variable name ="last_pos">
		<xsl:value-of select ="position()-1"/>
	</xsl:variable>
	<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"/>
</xsl:for-each>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Architect
Top Expert 2006
Commented:
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"/>

Author

Commented:
thx, very qucik reply that solved my problem!

Author

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

Commented:
welcome

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