<!--
  Naver2RSS - 공통 부분 XSLT
  누가: 신재호 <netj@sparcs.kaist.ac.kr>
  언제: 2004-01-03
  $Id: naver2rss.xsl,v 1.1 2004/01/03 04:47:19 netj Exp netj $

  자세한 내용은 http://sparcs.kaist.ac.kr/~netj/naver2rss/를 참고하세요.
-->
<xsl:stylesheet version="1.0"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:param name="title"/>
    <xsl:param name="url"/>
    <xsl:param name="TidyURL"
	select="'http://sparcs.kaist.ac.kr/~netj/naver2rss/tidy.cgi'"/>
    <xsl:template match="/">
	<rss version="2.0">
	    <channel>
		<title>네이버 <xsl:value-of select="$title"/> 뉴스</title>
		<link><xsl:value-of select="$url"/></link>
		<language>ko</language>
		<!-- 네이버 로고 (난 네이버랑 아무 상관 없는 사람인데 -_-) -->
		<image>
		    <title>네이버 뉴스</title>
		    <url>http://img.news.naver.com/image/news/images/slogo_naver_new.gif</url>
		    <link>http://news.naver.com/</link>
		</image>
		<description/>
		<!-- 이제 기사들 뽑아와서 뿌려주기. tidy가 정리해준 XHTML에는,
		a를 포함하는 각 td마다 기사가 들어있음 -->
		<xsl:apply-templates/>
	    </channel>
	</rss>
	<xsl:comment>Generated by Naver2RSS/1.1</xsl:comment>
    </xsl:template>

    <xsl:template match="text()"/>
    <xsl:template match="node()">
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template name="polish-url">
	<xsl:param name="url"/>
	<!-- 올바른 URL이 되도록 손보기 -->
	<xsl:if test="not(starts-with($url, 'http://'))">
	    <xsl:text>http://news.naver.com</xsl:text>
	</xsl:if>
	<xsl:value-of select="$url"/>
    </xsl:template>

    <!-- 어느 신문, 언제 썼는 지 알아내기 -->
    <xsl:template name="who-when">
	<xsl:param name="data"/>
	<xsl:variable name="author_date"
	    select="normalize-space(translate($data, '[]', '  '))"/>
	<xsl:variable name="author_year" select="substring-before($author_date, '-')"/>
	<xsl:variable name="author" select="substring($author_year, 1, string-length($author_year) - 5)"/><!-- XXX: Y10K problem here -->
	<xsl:variable name="date_time" select="normalize-space(substring-after($author_date, $author))"/>
	<xsl:variable name="date" select="substring-before($date_time, ' ')"/>
	<xsl:variable name="time" select="substring-after($date_time, ' ')"/>
	<author><xsl:value-of select="$author"/></author>
	<dc:date>
	    <xsl:value-of select="$date"/> <!-- 날짜 -->
	    <xsl:text>T</xsl:text> <!-- ISO 형식 맞춰주기 -->
	    <xsl:value-of select="$time"/> <!-- 시간 -->
	    <xsl:text>:00</xsl:text> <!-- 초는 없어서 그냥 00으로 -_- -->
	    <xsl:text>+09:00</xsl:text> <!-- 한국 표준시 -->
	</dc:date>
    </xsl:template>
</xsl:stylesheet>

