<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns='http://www.w3.org/2002/12/cal/ical#'
	xmlns:i='http://www.w3.org/2002/12/cal/ical#'
	xmlns:x='http://www.w3.org/2002/12/cal/prod/Apple_Comp_273def595c8b3485#'
	xmlns:rss="http://purl.org/rss/1.0/"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
	xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#"
	xmlns:foaf="http://xmlns.com/foaf/0.1/"
	xmlns:dc ="http://purl.org/dc/elements/1.1/"
	xmlns:dcterms="http://purl.org/dc/terms/"
	xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
	xmlns:date="http://exslt.org/dates-and-times"
	xmlns:hiroki="http://onohiroki.cycling.jp/ns/tool/"
	extension-element-prefixes="date i"
>

<!--
	iCalendar 由来の，連続したイベントや定期的なイベントを，1 日単位に展開する XSLT 
	毎月のイベントは対応しても，毎週のイベントには対応していない
-->


<!-- 2004-11-24T20:57 毎月あるイベントの処理の不具合を修正 -->
<!-- 2005-03-25T02:35 日付変更のイベントの処理の不具合を修正 -->

<xsl:output 
	method="xml"
	encoding="utf-8"
	indent="yes"
/> 

<xsl:variable name="now" select="date:date-time()"/>
<xsl:variable name="now1" select="'2005-04-01T00:00:00+09:00'"/>

<xsl:variable name="urlthisrdf" select="'http://onohiroki.cycling.jp/calendar/cycling-event-cal.rdf'"/>
<xsl:variable name="urlrss" select="'http://onohiroki.cycling.jp/calendar/current-cycling-event-rss.rdf'"/>
<xsl:variable name="urlhtml" select="'http://onohiroki.cycling.jp/calendar/calendar.html'"/>

<xsl:template match="/">
	<rdf:RDF>
		<Vcalendar>
			<xsl:apply-templates select="rdf:RDF/i:Vcalendar|rdf:RDF/i:vcalendar"/>
		</Vcalendar>
		<foaf:Person>
			<foaf:made rdf:resource=""/>
			<foaf:made>
				<xsl:attribute name="rdf:resource">
					<xsl:value-of select="$urlthisrdf"/>
				</xsl:attribute>
			</foaf:made>
			<foaf:made>
				<xsl:attribute name="rdf:resource">
					<xsl:value-of select="$urlrss"/>
				</xsl:attribute>
			</foaf:made>
			<foaf:made>
				<xsl:attribute name="rdf:resource">
					<xsl:value-of select="$urlhtml"/>
				</xsl:attribute>
			</foaf:made>
			<foaf:name>ONO Hiroki</foaf:name>
			<foaf:mbox_sha1sum>911143978a8ce9e254485ff4ee93ed5e700ddd74</foaf:mbox_sha1sum>
			<rdfs:seeAlso rdf:resource="http://onohiroki.cycling.jp/info/foaf.rdf" />
		</foaf:Person>
	</rdf:RDF>
</xsl:template>

<xsl:template match="i:Vcalendar|i:vcalendar">
	<xsl:apply-templates select="i:version|x:wrCalname|i:prodid|x:wrRelcalid|x:wrTimezone|i:calscale"/>
	<xsl:for-each select="i:component/i:Vevent|i:component/i:vevent">
	<xsl:sort select="i:dtstart/i:date|i:dtstart/i:dateTime"/>
		<xsl:choose>
			<xsl:when test="string(i:rrule/i:freq)= 'MONTHLY'">
				<!-- 毎月のイベントだったら -->
				
				<!-- 毎月のイベントは 3 ヶ月分だけ展開する 1/3 -->
				<xsl:comment>bydaynum: <xsl:value-of select="substring(i:rrule/i:byday,1,1)"/> |byday: <xsl:value-of select="substring(i:rrule/i:byday,2,2)"/></xsl:comment>
				<xsl:call-template name="day2num">
					<xsl:with-param name="bydaynum">
						<xsl:value-of select="substring(i:rrule/i:byday,1,1)"/>
					</xsl:with-param>
					<xsl:with-param name="byday">
						<xsl:value-of select="substring(i:rrule/i:byday,2,2)"/>
					</xsl:with-param>
					<xsl:with-param name="beginningofthismonth">
						<!-- この月の 1 日 -->
						<xsl:value-of select="date:add($now,concat('-P',concat(date:day-in-month($now),'D')))"/>
					</xsl:with-param>
					<xsl:with-param name="until">
						<xsl:value-of select="i:rrule/i:until"/>
					</xsl:with-param>
					<xsl:with-param name="end">0</xsl:with-param>
					<xsl:with-param name="uid"><xsl:value-of select="i:uid"/></xsl:with-param>
				</xsl:call-template>

				<!-- 毎月のイベントは 3 ヶ月分だけ展開する 2/3 -->
				<xsl:call-template name="day2num">
					<xsl:with-param name="bydaynum">
						<xsl:value-of select="substring(i:rrule/i:byday,1,1)"/>
					</xsl:with-param>
					<xsl:with-param name="byday">
						<xsl:value-of select="substring(i:rrule/i:byday,2,2)"/>
					</xsl:with-param>
					<xsl:with-param name="beginningofthismonth">
						<!-- この月の 1 日 -->
						<xsl:value-of select="date:add(date:add($now,'P1M'),concat('-P',concat(date:day-in-month($now),'D')))"/>
					</xsl:with-param>
					<xsl:with-param name="until">
						<xsl:value-of select="i:rrule/i:until"/>
					</xsl:with-param>
					<xsl:with-param name="end">0</xsl:with-param>
				<!-- <xsl:with-param name="uid"><xsl:value-of select="i:uid"/></xsl:with-param> -->
					<xsl:with-param name="uid"><xsl:value-of select="i:uid"/></xsl:with-param>
					
				</xsl:call-template>
				
				<!-- 毎月のイベントは 3 ヶ月分だけ展開する 3/3 -->
				<xsl:call-template name="day2num">
					<xsl:with-param name="bydaynum">
						<xsl:value-of select="substring(i:rrule/i:byday,1,1)"/>
					</xsl:with-param>
					<xsl:with-param name="byday">
						<xsl:value-of select="substring(i:rrule/i:byday,2,2)"/>
					</xsl:with-param>
					<xsl:with-param name="beginningofthismonth">
						<!-- この月の 1 日 -->
						<xsl:value-of select="date:add(date:add($now,'P2M'),concat('-P',concat(date:day-in-month($now),'D')))"/>
					</xsl:with-param>
					<xsl:with-param name="until">
						<xsl:value-of select="i:rrule/i:until"/>
					</xsl:with-param>
					<xsl:with-param name="end">0</xsl:with-param>
					<xsl:with-param name="uid"><xsl:value-of select="i:uid"/></xsl:with-param>
				</xsl:call-template>

				
			</xsl:when>

			<!-- イベントが日付変更の場合 -->
			<xsl:when test="i:recurrenceId">
				<xsl:choose>
					<xsl:when test="contains(date:difference($now,i:dtstart/i:dateTime),'-')">
						<xsl:comment>recurrenceId:<xsl:value-of select="i:dtstart/i:dateTime"/>
							<xsl:value-of select="i:summary"/> (イベントが日付変更の場合) <xsl:value-of 
							select="date:difference($now,i:dtstart/i:dateTime)"/>
						</xsl:comment>
					</xsl:when>
					<xsl:when test="contains(date:difference(substring-before($now,'T'),i:dtstart/i:date),'-')">
						<xsl:comment>recurrenceId:<xsl:value-of select="i:dtstart/i:date"/>
							<xsl:value-of select="i:summary"/> (イベントが日付変更の場合)<xsl:value-of 
							select="date:difference($now,i:dtstart/i:date)"/>
						</xsl:comment>
					</xsl:when>
					<xsl:otherwise>
						<component><Vevent>
							<xsl:comment>recurrenceId イベントが日付変更の場合</xsl:comment>
							<dtstart rdf:parseType="Resource">
								<!-- イベント開始 -->
								<xsl:choose>
									<xsl:when test="i:dtstart/i:date">
										<date><xsl:value-of select="i:dtstart/i:date"/></date>
									</xsl:when>
									<xsl:when test="i:dtstart/i:dateTime">
										<dateTime><xsl:value-of select="i:dtstart/i:dateTime"/></dateTime>
									</xsl:when>
								</xsl:choose>
							</dtstart>
			
							<xsl:choose>
							<xsl:when test="i:dtend/i:date">
								<dtend rdf:parseType="Resource">
									<date><xsl:value-of select="i:dtend/i:date"/></date>
								</dtend>
							</xsl:when>
							<xsl:when test="i:dtend/i:dateTime">
								<dtend rdf:parseType="Resource">
									<dateTime><xsl:value-of select="i:dtend/i:dateTime"/></dateTime>
								</dtend>
							</xsl:when>
							</xsl:choose>
							
		
							<summary><!-- 4 -->
								<!--<xsl:call-template name="recurrenceIdsummary">
									<xsl:with-param name="uid"><xsl:value-of select="i:uid"/></xsl:with-param>
								</xsl:call-template>-->
								<xsl:value-of select="i:summary"/>
							</summary>
		
							<uid><xsl:value-of select="i:uid"/></uid>
							<xsl:if test="i:sequence">
								<sequence><xsl:value-of select="i:sequence"/></sequence>
							</xsl:if>
							<xsl:if test="i:url">
								<url><xsl:attribute name="rdf:resource"><xsl:value-of select="i:url/@rdf:resource"/></xsl:attribute></url>
							</xsl:if>
							
							<xsl:if test="i:description">
								<description><xsl:value-of select="i:description"/></description>
							</xsl:if>
							<xsl:if test="i:duration">
								<duration><xsl:value-of select="i:duration"/></duration>
							</xsl:if>
							<xsl:if test="i:dtstamp">
								<dtstamp rdf:parseType='Resource'>
									<dateTime><xsl:value-of select="i:dtstamp/i:dateTime"/></dateTime>
								</dtstamp>
							</xsl:if>
						</Vevent></component>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>

			<!-- イベントが数日連続の場合 -->
			<xsl:when test="substring(date:difference(date:date(i:dtstart/i:date|i:dtstart/i:dateTime),date:add($now,concat('-P',concat(date:day-in-month($now),'D')))),1,1)='-'">
				<xsl:call-template name="eventconsecutive">
					<xsl:with-param name="beginning"><xsl:value-of select="i:dtstart/i:date|i:dtstart/i:dateTime"/></xsl:with-param>
					<xsl:with-param name="uid"><xsl:value-of select="i:uid"/></xsl:with-param>
				</xsl:call-template>
			</xsl:when>
					
			<xsl:otherwise>
				<xsl:comment>outdated:<xsl:value-of select="i:dtstart/i:date"/><xsl:value-of select="i:dtstart/i:dateTime"/><xsl:text> </xsl:text><xsl:value-of select="i:summary"/></xsl:comment>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>



<xsl:template match="i:version|x:wrCalname|i:prodid|x:wrRelcalid|x:wrTimezone|i:calscale">
	<xsl:copy>
		<xsl:value-of select="."/>
	</xsl:copy>
</xsl:template>

<!--<xsl:template match="i:vevent|i:Vevent">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
</xsl:template>-->


<xsl:template name="recurrenceIdsummary">
	<xsl:param name="uid" select="0" />
	<xsl:for-each select="/rdf:RDF/i:Vcalendar/i:component/i:Vevent">
	<xsl:if test="i:uid=$uid">
		<xsl:value-of select="i:summary"/>
	</xsl:if>
	</xsl:for-each>
</xsl:template>

<xsl:template name="recurrenceIduid">
	<xsl:param name="uid" select="0" />
	<xsl:param name="date" select="''" />
	<xsl:for-each select="/rdf:RDF/i:Vcalendar/i:component/i:Vevent">
		<xsl:if test="i:uid=$uid and contains(i:recurrenceId/i:dateTime, $date)">
			<xsl:comment><xsl:value-of select="$date"/></xsl:comment>
			<hiroki:recurrence>recurrence</hiroki:recurrence>
		</xsl:if>

	</xsl:for-each>
</xsl:template>

<xsl:template name="eventconsecutive">
	<!--
		連続したイベントに対する処理 
		再帰的な処理を行う
	-->
	<xsl:param name="beginning" select="date:add($now,'-P1M')"/>
	<!-- はじめは現在の P1M 前から -->
	<xsl:param name="uid" select="0" />
	<xsl:for-each select="/rdf:RDF/i:Vcalendar/i:component/i:Vevent">
	<xsl:if test="i:uid=$uid">
		<!-- 同じ uid であれば... -->
		<xsl:choose>
			<xsl:when test="substring(date:difference($beginning,date:date(i:dtend/i:date|i:dtend/i:dateTime)),2,1) &gt; 1">
			<component><Vevent>
				<xsl:comment>eventconsecutive</xsl:comment>
				<dtstart rdf:parseType="Resource">
					<!-- イベント開始 -->
					<xsl:choose>
						<xsl:when test="i:dtstart/i:date">
							<date><xsl:value-of select="$beginning"/></date>
						</xsl:when>
						<xsl:when test="i:dtstart/i:dateTime">
							<dateTime><xsl:value-of select="$beginning"/></dateTime>
						</xsl:when>
					</xsl:choose>
				</dtstart>

				<xsl:choose>
				<xsl:when test="i:dtend/i:date">
					<dtend rdf:parseType="Resource">
						<date><xsl:value-of select="i:dtend/i:date"/></date>
					</dtend>
				</xsl:when>
				<xsl:when test="i:dtend/i:dateTime">
					<dtend rdf:parseType="Resource">
						<dateTime><xsl:value-of select="i:dtend/i:dateTime"/></dateTime>
					</dtend>
				</xsl:when>
				</xsl:choose>
				
				<xsl:if test="i:summary">
					<summary><xsl:value-of select="i:summary"/></summary><!-- 3 -->
				</xsl:if>
				<uid><xsl:value-of select="i:uid"/></uid>
				<xsl:if test="i:sequence">
					<sequence><xsl:value-of select="i:sequence"/></sequence>
				</xsl:if>
				<xsl:if test="i:url">
					<url><xsl:attribute name="rdf:resource"><xsl:value-of select="i:url/@rdf:resource"/></xsl:attribute></url>
				</xsl:if>
				
				<xsl:if test="i:description">
					<description><xsl:value-of select="i:description"/></description>
				</xsl:if>
				<xsl:if test="i:duration">
					<duration><xsl:value-of select="i:duration"/></duration>
				</xsl:if>
				<xsl:if test="i:dtstamp">
					<dtstamp rdf:parseType='Resource'>
						<dateTime><xsl:value-of select="i:dtstamp/i:dateTime"/></dateTime>
					</dtstamp>
				</xsl:if>

			
			</Vevent></component>
			
			<xsl:call-template name="eventconsecutive">
				<xsl:with-param name="beginning"><xsl:value-of select="date:add($beginning,'P1D')"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="i:uid"/></xsl:with-param>
			</xsl:call-template>
				
			</xsl:when>
	
			<xsl:otherwise>
				<component><Vevent>
					<xsl:comment>end of eventconsecutive</xsl:comment>
					<dtstart rdf:parseType="Resource">
						<xsl:choose>
							<xsl:when test="i:dtstart/i:date">
								<date><xsl:value-of select="$beginning"/></date>
							</xsl:when>
							<xsl:when test="i:dtstart/i:dateTime">
								<dateTime><xsl:value-of select="$beginning"/></dateTime>
							</xsl:when>
						</xsl:choose>
					</dtstart>
					<xsl:choose>
					<xsl:when test="i:dtend/i:date">
						<dtend rdf:parseType="Resource">
							<date><xsl:value-of select="i:dtend/i:date"/></date>
						</dtend>
					</xsl:when>
					<xsl:when test="i:dtend/i:dateTime">
						<dtend rdf:parseType="Resource">
							<dateTime><xsl:value-of select="i:dtend/i:dateTime"/></dateTime>
						</dtend>
					</xsl:when>
					</xsl:choose>
					<xsl:if test="i:summary">
						<summary><xsl:value-of select="i:summary"/></summary><!-- 1 -->
					</xsl:if>
					<uid><xsl:value-of select="i:uid"/></uid>
					<xsl:if test="i:sequence">
						<sequence><xsl:value-of select="i:sequence"/></sequence>
					</xsl:if>
					<xsl:if test="i:url">
						<url><xsl:attribute name="rdf:resource"><xsl:value-of select="i:url/@rdf:resource"/></xsl:attribute></url>
					</xsl:if>
					<xsl:if test="i:description">
						<description><xsl:value-of select="i:description"/></description>
					</xsl:if>
					<xsl:if test="i:duration">
						<duration><xsl:value-of select="i:duration"/></duration>
					</xsl:if>
					<xsl:if test="i:dtstamp">
						<dtstamp rdf:parseType='Resource'>
							<dateTime><xsl:value-of select="i:dtstamp/i:dateTime"/></dateTime>
						</dtstamp>
					</xsl:if>
				</Vevent></component>
				
			</xsl:otherwise>
		</xsl:choose>
	</xsl:if>
	</xsl:for-each>
</xsl:template>



<xsl:template name="day2num">
	<!-- 毎月のイベントを展開する -->
	<xsl:param name="byday" select="AA" /><!-- 曜日 -->
	<xsl:param name="bydaynum" select="0" />
	<xsl:param name="beginningofthismonth" select="$now" />
	<xsl:param name="until" select="date:add($now,'P6M')" />
	<xsl:param name="end" select="0" />
	<xsl:param name="uid" select="0" />
	<xsl:choose>
		<xsl:when test="$byday='SU'">
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd">1</xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$bydaynum"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="$beginningofthismonth"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$until"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$byday='MO'">
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd">2</xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$bydaynum"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="$beginningofthismonth"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$until"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$byday='TU'">
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd">3</xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$bydaynum"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="$beginningofthismonth"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$until"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$byday='WE'">
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd">4</xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$bydaynum"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="$beginningofthismonth"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$until"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$byday='TH'">
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd">5</xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$bydaynum"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="$beginningofthismonth"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$until"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$byday='FR'">
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd">6</xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$bydaynum"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="$beginningofthismonth"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$until"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$byday='SA'">
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd">7</xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$bydaynum"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="$beginningofthismonth"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$until"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
	</xsl:choose>
</xsl:template>

<xsl:template name="seekbyday">
	<xsl:param name="nd" select="0" />
	<xsl:param name="nw" select="0" />
	<xsl:param name="dd" select="$beginningofthismonth" />
	<xsl:param name="ut" select="date:add($now,'P6M')" />
	<xsl:param name="end" select="0" />
	<xsl:param name="uid" select="0" />
	<xsl:comment> <xsl:value-of select="substring($dd,6,5)"/>|day-in-week:<xsl:value-of select="date:day-in-week($dd)"/> |day-of-week-in-month: <xsl:value-of select="date:day-of-week-in-month(date:add($dd,'-P1D'))"/> </xsl:comment>
	<xsl:choose>
		<xsl:when test="$nd=date:day-in-week($dd) and $nw=date:day-of-week-in-month(date:add($dd,'-P1D'))">
		
			<xsl:choose>
				<xsl:when test="not(substring(date:difference($dd,$ut),1,1)='-')">
					<component>
					<Vevent>
						<dtstart rdf:parseType='Resource'>
						<date><xsl:value-of select="substring($dd,1,10)"/></date>
						</dtstart>
						<dtend rdf:parseType='Resource'>
						<date><xsl:value-of select="substring(date:add($dd,'P1D'),1,10)"/></date>
						</dtend>
						<uid><xsl:value-of select="$uid"/></uid>
						
						
						<xsl:call-template name="recurrenceIduid">
							<xsl:with-param name="date"><xsl:value-of select="substring($dd,1,10)"/></xsl:with-param>
							<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
						</xsl:call-template>
						
						<xsl:for-each select="/rdf:RDF/i:Vcalendar/i:component/i:Vevent">
							<xsl:if test="i:uid=$uid"> 
								<xsl:if test="i:summary">
									<summary><xsl:value-of select="i:summary"/></summary><!-- 2 -->
								</xsl:if>
								<xsl:if test="i:sequence">
									<sequence><xsl:value-of select="i:sequence"/></sequence>
								</xsl:if>

								<xsl:if test="i:url">
									<url><xsl:attribute name="rdf:resource"><xsl:value-of select="i:url/@rdf:resource"/></xsl:attribute></url>
								</xsl:if>
								<xsl:if test="i:description">
									<description><xsl:value-of select="i:description"/></description>
								</xsl:if>
								<!--
								<rrule rdf:parseType='Resource'>
									<interval><xsl:value-of select="i:rrule/i:interval"/></interval>
									<freq><xsl:value-of select="i:rrule/i:freq"/></freq>
									<byday><xsl:value-of select="i:rrule/i:byday"/></byday>
									<xsl:if test="i:rrule/i:until">
										<until><xsl:value-of select="i:rrule/i:until"/></until>
									</xsl:if>
								</rrule>
								-->
							</xsl:if>
						</xsl:for-each>
					</Vevent>
					</component>
				</xsl:when>
				<xsl:otherwise><xsl:comment>outdated</xsl:comment></xsl:otherwise>

			</xsl:choose>
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="seekbyday">
				<xsl:with-param name="nd"><xsl:value-of select="$nd"/></xsl:with-param>
				<xsl:with-param name="nw"><xsl:value-of select="$nw"/></xsl:with-param>
				<xsl:with-param name="dd"><xsl:value-of select="date:add($dd,'P1D')"/></xsl:with-param>
				<xsl:with-param name="ut"><xsl:value-of select="$ut"/></xsl:with-param>
				<xsl:with-param name="uid"><xsl:value-of select="$uid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>


<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>


</xsl:stylesheet> 
