]> git.stg.codes - stg.git/blob - doc/xslt/website/rss.xsl
Version bump
[stg.git] / doc / xslt / website / rss.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:rss="http://purl.org/rss/1.0/"
4                 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
5                 xmlns:cvsf="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.CVS"
6                 xmlns:cvs="http://nwalsh.com/rdf/cvs#"
7                 xmlns:dc="http://purl.org/dc/elements/1.1/"
8                 exclude-result-prefixes="rss rdf cvs dc cvsf"
9                 version="1.0">
10
11 <xsl:output method="html"/>
12
13 <xsl:template match="rss">
14   <xsl:variable name="rss" select="document(@feed, .)"/>
15
16   <div class='rss'>
17     <xsl:choose>
18       <xsl:when test="not($rss)">
19         <xsl:message>RSS Failed: <xsl:value-of select="@feed"/></xsl:message>
20         <xsl:text>[RSS Failed: </xsl:text>
21         <xsl:value-of select="@feed"/>
22       </xsl:when>
23       <xsl:when test="$rss/rdf:RDF">
24         <xsl:apply-templates select="$rss/*/rss:channel"/>
25       </xsl:when>
26       <xsl:otherwise>
27         <!-- is there an otherwise case? -->
28         <xsl:apply-templates select="$rss//rss:channel"/>
29       </xsl:otherwise>
30     </xsl:choose>
31   </div>
32 </xsl:template>
33
34 <xsl:template match="rss:channel">
35   <xsl:variable name="image-resource" select="rss:image/@rdf:resource"/>
36   <xsl:variable name="image" select="//rss:image[@rdf:about = $image-resource]"/>
37
38   <xsl:if test="$image">
39     <xsl:choose>
40       <xsl:when test="$image/rss:link">
41         <a href="{$image/rss:link}">
42           <img src="{$image/rss:url}" alt="{$image/rss:title}" align="right" border="0"/>
43         </a>
44       </xsl:when>
45       <xsl:otherwise>
46         <img src="{$image/rss:url}" alt="{$image/rss:title}" align="right"/>
47       </xsl:otherwise>
48     </xsl:choose>
49   </xsl:if>
50
51   <xsl:apply-templates select="rss:title"/>
52   <xsl:apply-templates select="rss:description"/>
53   <xsl:apply-templates select="rss:items"/>
54
55   <xsl:if test="$image">
56     <br clear="right"/>
57   </xsl:if>
58 </xsl:template>
59
60 <xsl:template match="rss:title">
61   <xsl:param name="wrapper" select="'h3'"/>
62
63   <xsl:element name="{$wrapper}">
64     <xsl:choose>
65       <xsl:when test="../rss:link">
66         <a href="{../rss:link[1]}">
67           <xsl:apply-templates/>
68         </a>
69       </xsl:when>
70       <xsl:otherwise>
71         <xsl:apply-templates/>
72       </xsl:otherwise>
73     </xsl:choose>
74
75     <xsl:if test="../dc:date|../cvs:date">
76       <xsl:choose>
77         <xsl:when test="../dc:date">
78           <xsl:text> (</xsl:text>
79           <xsl:value-of select="../dc:date[1]"/>
80           <xsl:text>)</xsl:text>
81         </xsl:when>
82         <xsl:when test="function-available('cvsf:localTime')">
83           <xsl:variable name="timeString" select="cvsf:localTime(../cvs:date[1])"/>
84           <xsl:text> (</xsl:text>
85           <xsl:value-of select="substring($timeString, 1, 3)"/>
86           <xsl:text>, </xsl:text>
87           <xsl:value-of select="substring($timeString, 9, 2)"/>
88           <xsl:text> </xsl:text>
89           <xsl:value-of select="substring($timeString, 5, 3)"/>
90           <xsl:text> </xsl:text>
91           <xsl:value-of select="substring($timeString, 25, 4)"/>
92           <xsl:text>)</xsl:text>
93         </xsl:when>
94         <xsl:otherwise>
95           <xsl:value-of select="../cvs:date[1]"/>
96         </xsl:otherwise>
97       </xsl:choose>
98     </xsl:if>
99   </xsl:element>
100 </xsl:template>
101
102 <xsl:template match="rss:description">
103   <p>
104     <xsl:apply-templates/>
105   </p>
106 </xsl:template>
107
108 <xsl:template match="rss:items">
109   <dl>
110     <xsl:for-each select="rdf:Seq/rdf:li[@rdf:resource and @rdf:resource != '']">
111       <xsl:variable name="resource" select="@rdf:resource"/>
112       <xsl:variable name="item" select="//rss:item[@rdf:about = $resource]"/>
113       <xsl:if test="not($item)">
114         <xsl:message>
115           <xsl:text>RSS Warning: there is no item labelled: </xsl:text>
116           <xsl:value-of select="$resource"/>
117         </xsl:message>
118       </xsl:if>
119       <xsl:if test="count($item) &gt; 1">
120         <xsl:message>
121           <xsl:text>RSS Warning: there is more than one item labelled: </xsl:text>
122           <xsl:value-of select="$resource"/>
123         </xsl:message>
124       </xsl:if>
125       <xsl:apply-templates select="$item"/>
126     </xsl:for-each>
127   </dl>
128 </xsl:template>
129
130 <xsl:template match="rss:item">
131   <xsl:message>RSS item: <xsl:value-of select="rss:title"/></xsl:message>
132
133   <xsl:apply-templates select="rss:title">
134     <xsl:with-param name="wrapper" select="'dt'"/>
135   </xsl:apply-templates>
136   <xsl:if test="rss:description">
137     <dd>
138       <xsl:apply-templates select="rss:description"/>
139     </dd>
140   </xsl:if>
141 </xsl:template>
142
143 </xsl:stylesheet>