<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://purl.org/rss/1.0/"
	xmlns:rss="http://purl.org/rss/1.0/"
	xmlns:i='http://www.w3.org/2002/12/cal/ical#'
	xmlns:x='http://www.w3.org/2002/12/cal/prod/Apple_Comp_273def595c8b3485#'
	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:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:xhtml="http://www.w3.org/1999/xhtml"
	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 rss"
>

<xsl:output 
	method="xml"
	encoding="utf-8"
	indent="yes"
	
/> 
<!--cdata-section-elements="content:encoded"-->

<xsl:variable name="now" select="date:date-time()"/>
<xsl:variable name="kindofcalendar" select="'自転車イベント'"/>

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


<xsl:template match="/">
	<rdf:RDF>
		<xsl:apply-templates select="rdf:RDF/i:Vcalendar|rdf:RDF/i: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="$urlrical"/>
				</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">
<channel>
	<xsl:attribute name="rdf:about">
		<xsl:value-of select="$urlthisrdf"/>
	</xsl:attribute>
<title><xsl:value-of select="$kindofcalendar"/>カレンダー</title>
<dc:date><xsl:value-of select="$now"/></dc:date>
<description>
<xsl:value-of select="$kindofcalendar"/>のイベント情報
<!--<xsl:value-of select="i:prodid"/><xsl:value-of select="x:wrRelcalid"/>-->
</description>
<link><xsl:value-of select="$urlhtml"/></link>
<rdfs:seeAlso>
	<xsl:attribute name="rdf:resource">
		<xsl:value-of select="$urlrical"/>
	</xsl:attribute>
</rdfs:seeAlso>
<items>
<rdf:Seq>
<xsl:for-each select="i:component/i:Vevent|i:component/i:vevent">
<xsl:sort select="i:dtstart/i:date|i:dtstart/i:dateTime"/>
<rdf:li>
	
	<xsl:attribute name="rdf:resource">http://onohiroki.cycling.jp/calendar/cal<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,7)"/>.html#d<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,10)"/>-<xsl:value-of select="i:uid"/></xsl:attribute>
	<!--
	<xsl:attribute name="rdf:resource">http://onohiroki.cycling.jp/calendar/cal<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,7)"/>.html#uid<xsl:value-of select="i:uid"/></xsl:attribute>
	-->
	<!--<xsl:value-of select="i:summary"/>-->
</rdf:li>
</xsl:for-each>
</rdf:Seq>
</items>
</channel>

<xsl:for-each select="i:component/i:Vevent|i:component/i:vevent">
<xsl:sort select="i:dtstart/i:date|i:dtstart/i:dateTime"/>
<item>
	<xsl:attribute name="rdf:about">http://onohiroki.cycling.jp/calendar/cal<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,7)"/>.html#d<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,10)"/>-<xsl:value-of select="i:uid"/></xsl:attribute>
	<!--
	<xsl:attribute name="rdf:about">http://onohiroki.cycling.jp/calendar/cal<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,7)"/>.html#uid<xsl:value-of select="i:uid"/></xsl:attribute>
	-->

	<title><xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,10)"/><xsl:text> </xsl:text><xsl:value-of select="i:summary"/></title>
	<!--
	<link>http://onohiroki.cycling.jp/calendar/cal<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,7)"/>.html#d<xsl:value-of select="i:dtstart/i:date|i:dtstart/i:dateTime"/>-<xsl:value-of select="i:uid"/></link>
	-->
	<link>http://onohiroki.cycling.jp/calendar/cal<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,7)"/>.html#d<xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,1,4)"/><xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,6,2)"/><xsl:value-of select="substring(i:dtstart/i:date|i:dtstart/i:dateTime,9,2)"/></link>
	<xsl:if test="i:dtstamp/i:date|i:dtstamp/i:dateTime">
	<dc:date><xsl:value-of select="i:dtstamp/i:date|i:dtstamp/i:dateTime"/></dc:date>
	</xsl:if>
	<dc:subject><xsl:value-of select="$kindofcalendar"/></dc:subject>
	
	<description>イベント名:<xsl:value-of select="i:summary"/><xsl:text>, 開始日時:</xsl:text><xsl:value-of select="i:dtstart/i:date|i:dtstart/i:dateTime"/><xsl:text>, </xsl:text>
	
	<xsl:call-template name="stringreplace">
		<xsl:with-param name="string" select="string(i:description)" />
		<xsl:with-param name="search" select="'\n'" />
		<xsl:with-param name="replace" select="' '" />
		<xsl:with-param name="replacetag" select="''" />
	</xsl:call-template>
	<xsl:value-of select="i:url/@rdf:resource"/>
	</description>
	<content:encoded>
	<xsl:text> </xsl:text>
	<xsl:text disable-output-escaping="yes">&lt;</xsl:text>![CDATA[	
	<dl>
		<dt>イベント名</dt><dd class="event-name"><xsl:value-of select="i:summary"/></dd>
		<dt>開始日時</dt><dd class="dtstart"><xsl:value-of select="i:dtstart/i:date|i:dtstart/i:dateTime"/></dd>
		<dt>URL</dt><dd><a><xsl:attribute name="href"><xsl:value-of select="i:url/@rdf:resource"/></xsl:attribute><xsl:value-of select="i:url/@rdf:resource"/></a></dd>
	
	<xsl:if test="i:description">
	<dt>概要</dt>
	<dd><xsl:call-template name="stringreplace">
		<xsl:with-param name="string" select="string(i:description)" />
		<xsl:with-param name="search" select="'\n'" />
		<xsl:with-param name="replace" select="' '" />
		<xsl:with-param name="replacetag" select="'br'" />
	</xsl:call-template></dd>
	</xsl:if>
	</dl>
	
	]]<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
	</content:encoded>
		
		<foaf:topic xmlns='http://www.w3.org/2002/12/cal/ical#'>
			<xsl:copy-of select="."/>
		</foaf:topic>
</item>
</xsl:for-each>
</xsl:template>
<!--
<xsl:template match="i:vevent|i:Vevent">
	
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
	
	<xsl:copy-of select="." />
</xsl:template>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>
-->
<xsl:template name="stringreplace">
	<xsl:param name="string" select="''" />
	<xsl:param name="search" select="'¥n'" />
	<xsl:param name="replace" select="' '" />
	<xsl:param name="replacetag" select="''" />
	
	<xsl:choose>
	<xsl:when test="contains($string, $search)">
		<xsl:value-of select="substring-before($string,$search)"/>
		<xsl:choose>
			<xsl:when test="$replacetag = 'br'">
				<br />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$replace"/>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:call-template name="stringreplace">
			<xsl:with-param name="string" select="substring-after($string,$search)" />
			<xsl:with-param name="search" select="$search" />
			<xsl:with-param name="replace" select="$replace" />
			<xsl:with-param name="replacetag" select="$replacetag" />
		</xsl:call-template>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="$string"/>
	</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet> 
