[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Selecting parent node based upon child node value


Subject: [xsl] Selecting parent node based upon child node value
From: "David Steketee" <dsteketee@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 12 Oct 2006 09:18:28 -0400

I have an XSLT document which generates a calendar, and an XML document
which represents the month and events which occur within the month. I'm
using the XSLT parser in .NET 2.0 which I believe only supports XSLT 1.0.

The XML document is as follows:

<?xml version="1.0" encoding="utf-8"?>
<month start="1" days="31" num="10" year="2006" today="12">
	<name>October 2006</name>
	<Events>
		<Event>
	
<GroupGUID>7F4616F5-BEB6-4A68-87E9-3FAD45BD25CB</GroupGUID>
			<EventID>1</EventID>
			<EventTitle>Fundraiser</EventTitle>
			<StartDate>2006-10-09T00:00:00</StartDate>
			<EndDate>2006-10-11T00:00:00</EndDate>
			<Depth>1</Depth>
			<Date>
				<EventDateID>1</EventDateID>
				<EventDate>2006-10-09T00:00:00</EventDate>
	
<EventStartTime>2006-10-09T09:00:00</EventStartTime>
	
<EventEndTime>2006-10-09T21:00:00</EventEndTime>
			</Date>
			<Date>
				<EventDateID>2</EventDateID>
				<EventDate>2006-10-11T00:00:00</EventDate>
	
<EventStartTime>2006-10-11T09:00:00</EventStartTime>
	
<EventEndTime>2006-10-11T21:00:00</EventEndTime>
			</Date>
		</Event>
	</Events>
</month>

While generating the calendar, I need to determine if an Event node exists
where the EventDate is equal to the day being generated by the calendar XSLT
as it loops through all of the days of the month. If there is an event which
falls on that day, then I need to create a link which passes the EventID of
the Event which contains the Date.

The XSL document contains the following code where I'm attempting to perform
this "query".

      <xsl:when test="$index > $start - 1">
	<xsl:element name="td">
		<xsl:if test="($index - $start + 1) = $today">
			<xsl:attribute name="class">Today</xsl:attribute>

		</xsl:if>
		<xsl:element name="a">
			<xsl:attribute
name="href">javascript:void(0);</xsl:attribute>
			<xsl:value-of select="$index - $start + 1"/>
		</xsl:element>
        	</xsl:element>
      </xsl:when>
 
$index - $start + 1 is the number of the day being generated which would
match the EventDate of the Event. 

I've found a few examples elsewhere in the archive
(http://www.biglist.com/lists/xsl-list/archives/200207/msg01433.html) but
haven't been able to find anything which does what I need.

I could loop through all the events to determine if there is a match but
this seems wasteful and based upon the link above there seems to be a more
effective approach available, but unfortunately a bit beyond my
understanding of XSLT / XPATH.

Thank you in advance for any suggestions.

David Steketee


Current Thread
Keywords