[xsl] sort by xsl:if and then sort using templates?

Subject: [xsl] sort by xsl:if and then sort using templates?
From: "Max Bronsema" <max.bronsema@xxxxxxxxx>
Date: Mon, 20 Nov 2006 11:37:47 -0800
Hello list,

I am having trouble applying xsl:if statements when I have templates
within my XSLT document. Below is a summary of what I am trying to
accomplish. The main question I have is how do I sort using an if, and
then sort again using a template?

I pass in a parameter called "currentDate" which holds the current
date. I then wish to use an xsl:if statement to determine which xml
items are not past due. Using the if, as I understand acts as a
boolean statement, those that fit the bill stay and those that do not
are nixed.

After the if statement I try to sort my items by date using what seems
like a common way to sort by date using the substring method. This
works flawlessly until I try to nest it in my if statement.

Once the dates are sorted I wish to display the first five sorted
items. I have done this using a position() statement in the past. Is
there a better way to handle this?

Abridged version of xml file
-------------cal.xml --------------
		<title>City Council Meeting</title>

Important parts of xslt file
<!--Declare XSL Parameters -->
	<xsl:param name="currentDate"/>
<xsl:if test="/calendar/event/date/text() &gt;= $currentDate">

<xsl:template match="calendar">
		<xsl:sort select="substring(date, 7,4)"/>
		<xsl:sort select="substring(date, 1, 2)"/>
		<xsl:sort select="substring(date, 3, 2)"/>
	<xsl:template match="event">
   Date:      <xsl:apply-templates select="date"/>
   Title:     <xsl:apply-templates select="title"/>
   Time:    <xsl:apply-templates select="time"/>

Thank you for your help.

Max Bronsema

Current Thread