<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
	<xsl:variable name="title" select="/rss/channel/title"/>
	<xsl:template match="/">
		<xsl:element name="html">
			 <head>
				<title><xsl:value-of select="$title"/></title>
				<style type="text/css">
					body { font-family:Trebuchet MS; font-size:13px; color:#333; margin:10px 20px; padding:0; }
					a:link img, a:visited img { border:none; }
					ul, li { list-style:none; margin:0; padding:0; }
					h1, h4, h5, p { margin:0; padding:0; }
					img#feedImage { float:right; }
					div#feedContainer { margin:0; padding:0; }
					div#feedContainer h1 { letter-spacing:-1px; }
					div#feedReaders { padding:5px 0 15px 0; }
					div#feedReaders p { margin-bottom:5px; }
					div#feedItems li { margin-bottom:20px; }
					h4.itemTitle { font-size:18px; letter-spacing:-1px; border-top:1px solid silver; padding:5px 0; }
					h5.itemDate { font-size:12px; color:#666; padding-bottom:5px; }
				</style>
			</head>
			<xsl:apply-templates select="rss/channel"/>
		</xsl:element>
	</xsl:template>
	<xsl:template match="channel">
		<body>
			<div id="feedContainer">
				<div id="feedInfo">
					<xsl:apply-templates select="image"/>
					<h1>
						<xsl:choose>
							<xsl:when test="link">
								<a href="{normalize-space(link)}"><xsl:value-of select="$title"/></a>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$title"/>
							</xsl:otherwise>
						</xsl:choose>                  	
					</h1>
					<p style="clear:both"/>
				</div>
				<div id="feedReaders">
					<p>지금 구독하세요! RSS 구독기를 통하여 새글을 손쉽게 받아보실 수 있습니다.</p>
					<a href="javascript:document.location.href='http://www.hanrss.com/add_sub.qst?url='+encodeURIComponent(document.location.href)" title="한RSS에 추가"><img src="http://static.hanrss.com/images/add_to_hanrss2.gif" width="80" height="15" alt="한RSS에 추가" /></a>
				</div>
				<div id="feedItems">
					<ul>
						<xsl:apply-templates select="item"/>
					</ul>
				</div>
			</div>
		</body>
	</xsl:template>
	<xsl:template match="image">
		<a href="{normalize-space(link)}" title="{title}"><img src="{url}" id="feedImage" alt="{title}"/></a>
		<xsl:text/>
	</xsl:template>
	<xsl:template match="item" xmlns:dc="http://purl.org/dc/elements/1.1/">
		<li>
			<h4 class="itemTitle">
				<xsl:choose>
					<xsl:when test="guid[@isPermaLink='true' or not(@isPermaLink)]">
						<a href="{normalize-space(guid)}"><xsl:value-of select="title"/></a>
					</xsl:when>
					<xsl:when test="link">
						<a href="{normalize-space(link)}"><xsl:value-of select="title"/></a>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="title"/>
					</xsl:otherwise>
				</xsl:choose>
			</h4>      
			<h5 class="itemDate">
				<xsl:if test="count(child::pubDate)=1"><xsl:value-of select="pubDate"/></xsl:if>
				<xsl:if test="count(child::dc:date)=1"><xsl:value-of select="dc:date"/></xsl:if>
			</h5>
			<div class="itemContent">
				<xsl:call-template name="outputContent"/>
			</div>
		</li>
	</xsl:template>
	<xsl:template name="outputContent">
		<xsl:choose>
			<xsl:when xmlns:xhtml="http://www.w3.org/1999/xhtml" test="xhtml:body">
				<xsl:copy-of select="xhtml:body/*"/>
			</xsl:when>
			<xsl:when xmlns:xhtml="http://www.w3.org/1999/xhtml" test="xhtml:div">
				<xsl:copy-of select="xhtml:div"/>
			</xsl:when>
			<xsl:when xmlns:content="http://purl.org/rss/1.0/modules/content/" test="content:encoded">
				<xsl:value-of select="content:encoded" disable-output-escaping="yes"/>
			</xsl:when>
			<xsl:when test="description">
				<xsl:value-of select="description" disable-output-escaping="yes"/>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
