79d16622c25fae8b5f90e8b5359b03d76bd5fb64
[tweeper.git] / twitter_user_timeline2rss.xsl
1 <!--
2   Stylesheet to convert Twitter user timelines to RSS.
3
4   Copyright (C) 2013  Antonio Ospite <ospite@studenti.unina.it>
5
6   This file is part of tweeper.
7
8   This program is free software: you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation, either version 3 of the License, or
11   (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 -->
21 <xsl:stylesheet version="1.0"
22     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
23
24     <xsl:output method="xml" indent="yes"/>
25
26     <xsl:variable name="twitterBaseURL">
27         <xsl:text>https://twitter.com</xsl:text>
28     </xsl:variable>
29
30     <xsl:variable name="screen-name" select="//div[@class='profile-card-inner']/@data-screen-name"/>
31
32     <!-- TODO: make URLs hyperlinked (http://www.dpawson.co.uk/xsl/rev2/regex2.html) -->
33     <xsl:template name="tweet" match="//p[@class='js-tweet-text tweet-text']">
34         <xsl:value-of select="$screen-name"/>: <xsl:value-of select=".//p[@class='js-tweet-text tweet-text']"/>
35     </xsl:template>
36
37     <xsl:template match="//div[@id='timeline']//ol[@id='stream-items-id']//li[@data-item-type='tweet']">
38         <item>
39             <title>
40                 <xsl:call-template name="tweet"/>
41             </title>
42             <link>
43                 <xsl:value-of select="$twitterBaseURL"/><xsl:value-of select=".//a[@class='details with-icn js-details']/@href"/>
44             </link>
45             <pubDate>
46                 <xsl:value-of select=".//small[@class='time']//span/@data-time"/>
47             </pubDate>
48             <description>
49                 <xsl:call-template name="tweet"/>
50             </description>
51         </item>
52     </xsl:template>
53
54     <xsl:template match="/">
55
56         <rss version="2.0">
57             <channel>
58                 <generator>Tweeper</generator>
59                 <title>
60                     <xsl:text>Twitter / </xsl:text><xsl:value-of select="$screen-name"/>
61                 </title>
62                 <link>
63                     <xsl:value-of select="//link[@rel='canonical']/@href"/>
64                 </link>
65                 <description>
66                     <xsl:value-of select="//meta[@name='description']/@content"/>
67                 </description>
68                 <image>
69                     <url>
70                         <xsl:value-of select="//a[@class='profile-picture media-thumbnail']/@href"/>
71                     </url>
72                 </image>
73                 <xsl:apply-templates select="//div[@id='timeline']//ol[@id='stream-items-id']//li[@data-item-type='tweet']"/>
74             </channel>
75         </rss>
76     </xsl:template>
77 </xsl:stylesheet>