~lattis/rss

rss/process.xslt -rw-r--r-- 2.5 KiB View raw
e6ded571Stone Tickle add a license a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:str="http://exslt.org/strings"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <xsl:output method="html"/>

  <xsl:param name="target_dir" select="target_dir"/>
  <xsl:param name="feed_name" select="feed_name"/>

  <xsl:template match="item">
    <xsl:variable name="raw_date" select="str:tokenize(pubDate, ' ')" />
    <xsl:variable name="month_num">
      <xsl:if test="$raw_date[3]='Jan'"> <xsl:value-of select="'01'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Feb'"> <xsl:value-of select="'02'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Mar'"> <xsl:value-of select="'03'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Apr'"> <xsl:value-of select="'04'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='May'"> <xsl:value-of select="'05'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Jun'"> <xsl:value-of select="'06'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Jul'"> <xsl:value-of select="'07'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Aug'"> <xsl:value-of select="'08'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Sep'"> <xsl:value-of select="'09'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Oct'"> <xsl:value-of select="'10'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Nov'"> <xsl:value-of select="'11'"/> </xsl:if>
      <xsl:if test="$raw_date[3]='Dec'"> <xsl:value-of select="'12'"/> </xsl:if>
    </xsl:variable>

    <xsl:variable name="date" select="concat(
      format-number($raw_date[4],'0000'), '/',
      format-number($month_num,'00'), '/',
      format-number($raw_date[2],'00'), '/',
      $raw_date[5]
    )" />

    <xsl:variable name="title" select="translate(substring(title,0,70),'/','_')" />
    <!-- <xsl:variable name="feed_name" select="../title" /> -->
    <xsl:variable name="link" select="link" />

    <xsl:document href="{$target_dir}/{$feed_name}/{$date} - {$title}">
      <a href="{$link}">
        <xsl:value-of select="link"/>
      </a>
      <p><xsl:value-of select="pubDate"/></p>
      <h1><xsl:value-of select="title"/></h1>
      <xsl:choose>
        <xsl:when test="content:encoded">
          <xsl:value-of select="content:encoded" disable-output-escaping="yes"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="description" disable-output-escaping="yes"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:document>
  </xsl:template>

  <xsl:template match = "/rss/channel">
    <xsl:apply-templates select="item"/>
  </xsl:template>
</xsl:stylesheet>