Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/ https://fsfe.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
10KB

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- XSL stylesheet for generation RSS feeds. It's currently using RSS 2.0. -->
  3. <xsl:stylesheet version="1.0"
  4. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5. xmlns:dt="http://xsltsl.org/date-time"
  6. xmlns:weekdays="."
  7. xmlns:months="."
  8. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  9. xmlns:atom="http://www.w3.org/2005/Atom">
  10. <xsl:import href="date-time.xsl" />
  11. <xsl:output method="xml" encoding="utf-8" indent="yes"/>
  12. <!-- $today = current date (given as <html date="...">) -->
  13. <xsl:variable name="today">
  14. <xsl:value-of select="/html/@date" />
  15. </xsl:variable>
  16. <!-- ======== -->
  17. <!-- Weekdays -->
  18. <!-- ======== -->
  19. <weekdays:weekday-names>
  20. <weekdays:day ref="0">Sun</weekdays:day> <!-- it seems that the module returns 0 for Sunday, on the "English" calendar model (Sundays first) -->
  21. <weekdays:day ref="1">Mon</weekdays:day>
  22. <weekdays:day ref="2">Tue</weekdays:day>
  23. <weekdays:day ref="3">Wed</weekdays:day>
  24. <weekdays:day ref="4">Thu</weekdays:day>
  25. <weekdays:day ref="5">Fri</weekdays:day>
  26. <weekdays:day ref="6">Sat</weekdays:day>
  27. <weekdays:day ref="7">Sun</weekdays:day>
  28. </weekdays:weekday-names>
  29. <!-- ====== -->
  30. <!-- Months -->
  31. <!-- ====== -->
  32. <months:month-names>
  33. <months:month ref="01">Jan</months:month>
  34. <months:month ref="02">Feb</months:month>
  35. <months:month ref="03">Mar</months:month>
  36. <months:month ref="04">Apr</months:month>
  37. <months:month ref="05">May</months:month>
  38. <months:month ref="06">Jun</months:month>
  39. <months:month ref="07">Jul</months:month>
  40. <months:month ref="08">Aug</months:month>
  41. <months:month ref="09">Sep</months:month>
  42. <months:month ref="10">Oct</months:month>
  43. <months:month ref="11">Nov</months:month>
  44. <months:month ref="12">Dec</months:month>
  45. </months:month-names>
  46. <!-- ============= -->
  47. <!-- Link handling -->
  48. <!-- ============= -->
  49. <xsl:template match="link">
  50. <xsl:param name="lang" />
  51. <!-- Original link text -->
  52. <xsl:variable name="link">
  53. <xsl:value-of select="normalize-space(.)" />
  54. </xsl:variable>
  55. <!-- Add leading "http://fsfe.org" if necessary -->
  56. <xsl:variable name="full-link">
  57. <xsl:choose>
  58. <xsl:when test="starts-with ($link, 'http:')">
  59. <xsl:value-of select="$link" />
  60. </xsl:when>
  61. <xsl:when test="starts-with ($link, 'https:')">
  62. <xsl:value-of select="$link" />
  63. </xsl:when>
  64. <xsl:otherwise>http://fsfe.org<xsl:value-of select="$link" />
  65. </xsl:otherwise>
  66. </xsl:choose>
  67. </xsl:variable>
  68. <!-- Insert language into link -->
  69. <xsl:choose>
  70. <xsl:when test="starts-with ($full-link, 'http://www.fsfeurope.org/')
  71. and substring-before ($full-link, '.html') != ''">
  72. <xsl:value-of select="concat (substring-before ($full-link, '.html'),
  73. '.', $lang, '.html')" />
  74. </xsl:when>
  75. <xsl:otherwise>
  76. <xsl:value-of select="$full-link" />
  77. </xsl:otherwise>
  78. </xsl:choose>
  79. </xsl:template>
  80. <!-- ============ -->
  81. <!-- Main routine -->
  82. <!-- ============ -->
  83. <xsl:template match="html">
  84. <!-- Language -->
  85. <xsl:variable name="lang">
  86. <xsl:value-of select="@lang" />
  87. </xsl:variable>
  88. <!-- Header -->
  89. <rss version="2.0">
  90. <channel>
  91. <title>FSFE News</title>
  92. <description>News from the Free Software Foundation Europe</description>
  93. <link>http://fsfe.org/news/</link>
  94. <language><xsl:value-of select="$lang" /></language>
  95. <copyright>Copyright (c) Free Software Foundation Europe. Verbatim copying and distribution
  96. of this entire article is permitted in any medium, provided this
  97. notice is preserved.</copyright>
  98. <managingEditor>press@fsfeurope.org (FSFE Press Team)</managingEditor>
  99. <webMaster>web@fsfeurope.org (FSFE Webmaster Team)</webMaster>
  100. <image>
  101. <url>http://fsfe.org/news/fsfe-news.png</url>
  102. <title>FSFE News</title>
  103. <width>88</width>
  104. <height>31</height>
  105. <link>http://fsfe.org/news/</link>
  106. </image>
  107. <xsl:element name="atom:link">
  108. <xsl:attribute name="href">http://fsfe.org/news/news.<xsl:value-of select="$lang"/>.rss</xsl:attribute>
  109. <xsl:attribute name="rel">self</xsl:attribute>
  110. <xsl:attribute name="type">application/rss+xml</xsl:attribute>
  111. </xsl:element>
  112. <!-- News items -->
  113. <xsl:for-each select="/html/set/news
  114. [translate (@date, '-', '') &lt;= translate ($today, '-', '')]">
  115. <xsl:sort select="@date" order="descending"/>
  116. <xsl:if test="position() &lt; 11">
  117. <xsl:element name="item">
  118. <!-- guid -->
  119. <xsl:element name="guid">
  120. <xsl:attribute name="isPermaLink">false</xsl:attribute>
  121. <xsl:value-of select="@filename"/>
  122. </xsl:element>
  123. <!-- Title -->
  124. <xsl:element name="title">
  125. <xsl:value-of select="title"/>
  126. </xsl:element>
  127. <!-- News description -->
  128. <xsl:element name="description">
  129. <xsl:copy-of select="normalize-space(body)"/>
  130. <xsl:text>
  131. Support FSFE, join the Fellowship: https://fellowship.fsfe.org/login/join.php
  132. Make a one time donation: http://fsfe.org/donate/donate.html</xsl:text>
  133. </xsl:element>
  134. <!-- News body -->
  135. <xsl:element name="content:encoded">
  136. <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
  137. <xsl:choose>
  138. <xsl:when test="body-complete">
  139. <xsl:apply-templates select="body-complete/*"/>
  140. </xsl:when>
  141. <xsl:otherwise>
  142. <xsl:copy-of select="normalize-space(body)"/>
  143. </xsl:otherwise>
  144. </xsl:choose>
  145. <xsl:element name="p">
  146. <xsl:text>Support FSFE, </xsl:text>
  147. <xsl:element name="a">
  148. <xsl:attribute name="href">https://fellowship.fsfe.org/login/join.php</xsl:attribute>
  149. <xsl:text>join the Fellowship</xsl:text>
  150. </xsl:element>
  151. <xsl:element name="br" />
  152. <xsl:text>Make a </xsl:text>
  153. <xsl:element name="a">
  154. <xsl:attribute name="href">http://fsfe.org/donate/donate.html</xsl:attribute>
  155. <xsl:text>one time donation</xsl:text>
  156. </xsl:element>
  157. </xsl:element>
  158. <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
  159. </xsl:element>
  160. <!-- Link -->
  161. <xsl:if test="link != ''">
  162. <xsl:variable name="link">
  163. <xsl:apply-templates select="link">
  164. <xsl:with-param name="lang" select="$lang" />
  165. </xsl:apply-templates>
  166. </xsl:variable>
  167. <xsl:element name="link">
  168. <xsl:value-of select="normalize-space($link)" />
  169. </xsl:element>
  170. </xsl:if>
  171. <!-- Date -->
  172. <xsl:element name="pubDate">
  173. <xsl:variable name="day-of-week">
  174. <xsl:call-template name="dt:calculate-day-of-the-week">
  175. <xsl:with-param name="year" select="substring(@date, 0, 5)" />
  176. <xsl:with-param name="month" select="substring(@date, 6, 2)" />
  177. <xsl:with-param name="day" select="substring(@date, 9, 2)" />
  178. </xsl:call-template>
  179. </xsl:variable>
  180. <xsl:value-of select="document('')/*/weekdays:weekday-names/weekdays:day[@ref=$day-of-week]" />
  181. <xsl:text>, </xsl:text>
  182. <xsl:value-of select="substring-after(substring-after(@date, '-'), '-')" />
  183. <xsl:variable name="month">
  184. <xsl:value-of select="substring-before(substring-after(@date, '-'), '-')" />
  185. </xsl:variable>
  186. <xsl:text> </xsl:text>
  187. <xsl:value-of select="document('')/*/months:month-names/months:month[@ref=$month]" />
  188. <xsl:text> </xsl:text>
  189. <xsl:value-of select="substring-before(@date, '-')" />
  190. <xsl:text> 00:00:00 +0100</xsl:text>
  191. </xsl:element>
  192. </xsl:element>
  193. </xsl:if>
  194. </xsl:for-each>
  195. <!-- Footer -->
  196. </channel>
  197. </rss>
  198. </xsl:template>
  199. <!-- take care that links within <content:encoded> are not relative -->
  200. <xsl:template match="a">
  201. <xsl:element name="a">
  202. <xsl:attribute name="href">
  203. <xsl:choose>
  204. <xsl:when test="substring(@href,1,1) = '/'">
  205. <xsl:text>http://fsfe.org</xsl:text>
  206. <xsl:value-of select="@href" />
  207. </xsl:when>
  208. <xsl:otherwise>
  209. <xsl:value-of select="@href" />
  210. </xsl:otherwise>
  211. </xsl:choose>
  212. </xsl:attribute>
  213. <xsl:value-of select="." />
  214. </xsl:element>
  215. </xsl:template>
  216. <!-- remove newsteaser from <p> -->
  217. <xsl:template match="p">
  218. <xsl:element name="p">
  219. <xsl:apply-templates select="node()" />
  220. </xsl:element>
  221. </xsl:template>
  222. <!-- as well as images -->
  223. <xsl:template match="img">
  224. <xsl:element name="img">
  225. <xsl:attribute name="src">
  226. <xsl:choose>
  227. <xsl:when test="substring(@src,1,1) = '/'">
  228. <xsl:text>http://fsfe.org</xsl:text>
  229. <xsl:value-of select="@src" />
  230. </xsl:when>
  231. <xsl:otherwise>
  232. <xsl:value-of select="@src" />
  233. </xsl:otherwise>
  234. </xsl:choose>
  235. </xsl:attribute>
  236. </xsl:element>
  237. </xsl:template>
  238. <!-- Do not copy <body-complete> to output at all -->
  239. <xsl:template match="body-complete"/>
  240. <!-- For all other nodes, copy verbatim -->
  241. <xsl:template match="@*|node()" priority="-1">
  242. <xsl:copy>
  243. <xsl:apply-templates select="@*|node()"/>
  244. </xsl:copy>
  245. </xsl:template>
  246. </xsl:stylesheet>