Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
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.

tagging.xsl 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:dt="http://xsltsl.org/date-time">
  5. <xsl:import href="date-time.xsl" />
  6. <xsl:import href="feeds.xsl" />
  7. <xsl:import href="events-utils.xsl" />
  8. <xsl:output method="xml" encoding="UTF-8" indent="yes" />
  9. <!--display dynamic list of tagged news items-->
  10. <xsl:template name="fetch-news">
  11. <xsl:param name="tag" select="''"/>
  12. <xsl:param name="today" select="/html/@date" />
  13. <xsl:param name="nb-items" select="''" />
  14. <xsl:param name="display-year" select="'no'" />
  15. <xsl:param name="show-date" select="'yes'" />
  16. <xsl:param name="compact-view" select="'no'" />
  17. <xsl:for-each select="/html/set/news[ translate (@date, '-', '') &lt;= translate ($today, '-', '')
  18. and (tags/tag = $tag or $tag='')
  19. and tags/tag != 'newsletter'
  20. and not( @type = 'newsletter' ) ]">
  21. <!-- @type != 'newsletter' is for legacy -->
  22. <xsl:sort select="@date" order="descending" />
  23. <xsl:if test="position() &lt;= $nb-items or $nb-items=''">
  24. <xsl:call-template name="news">
  25. <xsl:with-param name="show-date" select="$show-date" />
  26. <xsl:with-param name="compact-view" select="$compact-view" />
  27. <xsl:with-param name="display-year" select="$display-year" />
  28. </xsl:call-template>
  29. </xsl:if>
  30. </xsl:for-each>
  31. </xsl:template>
  32. <!--display dynamic list of (not yet tagged) newsletters items-->
  33. <xsl:template name="fetch-newsletters">
  34. <xsl:param name="today" select="/html/@date" />
  35. <xsl:param name="nb-items" select="''" />
  36. <xsl:for-each select="/html/set/news [translate(@date, '-', '') &lt;= translate($today, '-', '')
  37. and (tags/tag = 'newsletter'
  38. or @type = 'newsletter' ) ]"> <!-- @type = 'newsletter' is for legacy -->
  39. <xsl:sort select="@date" order="descending" />
  40. <xsl:if test="position()&lt;= $nb-items or $nb-items=''">
  41. <xsl:call-template name="newsletter" />
  42. </xsl:if>
  43. </xsl:for-each>
  44. </xsl:template>
  45. <!--display dynamic list of tagged event items-->
  46. <xsl:template name="fetch-events">
  47. <xsl:param name="tag" select="''"/>
  48. <xsl:param name="today" select="/html/@date" />
  49. <xsl:param name="wanted-time" select="future" /> <!-- value in {"past", "present", "future"} -->
  50. <xsl:param name="header" select="''" />
  51. <xsl:param name="nb-items" select="''" />
  52. <xsl:param name="display-details" select="'no'" />
  53. <xsl:param name="display-year" select="'no'" />
  54. <xsl:choose>
  55. <xsl:when test="$wanted-time = 'past'">
  56. <!-- Past events -->
  57. <xsl:for-each select="/html/set/event [translate (@end, '-', '') &lt; translate ($today, '-', '') and (tags/tag = $tag or $tag='') ]">
  58. <xsl:sort select="@end" order="descending" />
  59. <xsl:if test="position() &lt;= $nb-items or $nb-items=''">
  60. <xsl:call-template name="event">
  61. <xsl:with-param name="header" select="$header" />
  62. <xsl:with-param name="display-details" select="$display-details" />
  63. <xsl:with-param name="display-year" select="$display-year" />
  64. </xsl:call-template>
  65. </xsl:if>
  66. </xsl:for-each>
  67. </xsl:when>
  68. <xsl:when test="$wanted-time = 'present'">
  69. <!-- Current events -->
  70. <xsl:for-each select="/html/set/event
  71. [translate (@start, '-', '') &lt;= translate ($today, '-', '') and
  72. translate (@end, '-', '') &gt;= translate ($today, '-', '') and
  73. (tags/tag = $tag or $tag='') ]">
  74. <xsl:sort select="@start" order="descending" />
  75. <xsl:if test="position() &lt;= $nb-items or $nb-items=''">
  76. <xsl:call-template name="event">
  77. <xsl:with-param name="header" select="$header" />
  78. <xsl:with-param name="display-details" select="$display-details" />
  79. <xsl:with-param name="display-year" select="$display-year" />
  80. </xsl:call-template>
  81. </xsl:if>
  82. </xsl:for-each>
  83. </xsl:when>
  84. <xsl:otherwise> <!-- if we were not told what to do, display future events -->
  85. <!-- Future events -->
  86. <xsl:for-each select="/html/set/event
  87. [translate (@start, '-', '') &gt; translate ($today, '-', '') and (tags/tag = $tag or $tag='') ]">
  88. <xsl:sort select="@start" />
  89. <xsl:if test="position() &lt;= $nb-items or $nb-items=''">
  90. <xsl:call-template name="event">
  91. <xsl:with-param name="header" select="$header" />
  92. <xsl:with-param name="display-details" select="$display-details" />
  93. <xsl:with-param name="display-year" select="$display-year" />
  94. </xsl:call-template>
  95. </xsl:if>
  96. </xsl:for-each>
  97. </xsl:otherwise>
  98. </xsl:choose>
  99. </xsl:template>
  100. <xsl:key name="news-tags-by-value" match="news/tags/tag" use="."/>
  101. <!--display dynamic list of tags used in news-->
  102. <xsl:template name="all-tags-news">
  103. <!-- <xsl:variable name="nbtags" select="count(
  104. /html/set/news/tags/tag[
  105. count( . | key( 'news-tags-by-value', . )[1] ) = 1
  106. ])" />
  107. <xsl:variable name="average" select="count(/html/set/news/tags/tag) div $nbtags" />
  108. ##<xsl:value-of select="$nbtags" />##<xsl:value-of select="$average" />## -->
  109. <xsl:call-template name="append-children-tags" />
  110. <!--
  111. <xsl:for-each select="/html/set/news/tags/tag">
  112. <xsl:sort select="." order="ascending" />
  113. <xsl:variable name="thistag" select="node()" />
  114. <xsl:variable name="nb" select="count( /html/set/news/tags/tag[text() = $thistag]) " />
  115. <xsl:if test="generate-id() = generate-id(key('news-tags-by-value', normalize-space(.)))">
  116. <xsl:element name="li">
  117. <xsl:element name="a">
  118. <xsl:attribute name="href">
  119. <xsl:text>/tags/tagged.</xsl:text>
  120. <xsl:value-of select="/html/@lang" />
  121. <xsl:text>.html#n</xsl:text>
  122. <xsl:value-of select="translate($thistag,' ','')" />
  123. </xsl:attribute>
  124. <xsl:value-of select="."/>
  125. </xsl:element>
  126. </xsl:element>
  127. </xsl:if>
  128. </xsl:for-each>
  129. -->
  130. </xsl:template>
  131. <xsl:key name="events-tags-by-value" match="event/tags/tag" use="."/>
  132. <!--display dynamic list of tags used in events-->
  133. <xsl:template name="all-tags-events">
  134. <xsl:element name="ul">
  135. <xsl:attribute name="class">taglist</xsl:attribute>
  136. <xsl:for-each select="/html/set/event/tags/tag">
  137. <xsl:sort select="." order="ascending" />
  138. <xsl:variable name="thistag" select="node()" />
  139. <xsl:if test="generate-id() = generate-id(key('events-tags-by-value', normalize-space(.)))">
  140. <xsl:element name="li">
  141. <xsl:element name="a">
  142. <xsl:attribute name="href">
  143. <xsl:text>/tags/tagged.</xsl:text>
  144. <xsl:value-of select="/html/@lang" />
  145. <xsl:text>.html#e</xsl:text>
  146. <xsl:value-of select="translate($thistag,' ','')" />
  147. </xsl:attribute>
  148. <xsl:value-of select="."/>
  149. </xsl:element>
  150. </xsl:element>
  151. </xsl:if>
  152. </xsl:for-each>
  153. </xsl:element>
  154. </xsl:template>
  155. <!-- recursive, nested list of parent-region children tags -->
  156. <xsl:template name="append-children-tags">
  157. <xsl:param name="parent-region" select="''" />
  158. <xsl:element name="ul">
  159. <xsl:if test="$parent-region=''">
  160. <xsl:attribute name="class">taglist</xsl:attribute>
  161. </xsl:if>
  162. <xsl:attribute name="parent-region"><xsl:value-of select="$parent-region" /></xsl:attribute>
  163. <xsl:for-each select="/html/set/tag[ (not(@parent-region) and $parent-region='') or
  164. @parent-region = $parent-region ]">
  165. <xsl:variable name="id" select="@id" />
  166. <!-- <xsl:variable name="nb" select="count( /html/set/news/tags/tag[text() = $id]) " /> -->
  167. <xsl:element name="li">
  168. <xsl:element name="a">
  169. <xsl:attribute name="href">
  170. <xsl:text>/tags/tagged.</xsl:text>
  171. <xsl:value-of select="/html/@lang" />
  172. <xsl:text>.html#n</xsl:text>
  173. <xsl:value-of select="translate($id,' ','')" />
  174. </xsl:attribute>
  175. <xsl:value-of select="@name"/>
  176. </xsl:element>
  177. <!-- if there are children, add them as a sublist -->
  178. <xsl:for-each select="/html/set/tag[ @parent-region = $id ]">
  179. <xsl:call-template name="append-children-tags">
  180. <xsl:with-param name="parent-region" select="$id" />
  181. </xsl:call-template>
  182. </xsl:for-each>
  183. </xsl:element> <!-- </li> -->
  184. </xsl:for-each>
  185. </xsl:element> <!-- </ul> -->
  186. </xsl:template>
  187. <xsl:template name="fetch-links">
  188. <xsl:element name="ul">
  189. <xsl:for-each select="/html/set/link">
  190. <xsl:element name="li">
  191. <xsl:element name="a">
  192. <xsl:attribute name="href">
  193. <xsl:value-of select="href" />
  194. </xsl:attribute>
  195. <xsl:value-of select="title"/>
  196. </xsl:element>
  197. <xsl:if test="description">
  198. <xsl:element name="p">
  199. <xsl:value-of select="description"/>
  200. </xsl:element>
  201. </xsl:if>
  202. </xsl:element>
  203. </xsl:for-each>
  204. </xsl:element>
  205. </xsl:template>
  206. <!--display dynamic list of tagged news, sorted by tag -->
  207. <xsl:template name="tagged-news">
  208. <!-- loop through all tags (this complex expression loops over each tag once) -->
  209. <xsl:for-each select="/html/set/news/tags/tag[ count( . | key( 'news-tags-by-value', . )[1] ) = 1 ]">
  210. <xsl:sort select="." order="ascending" />
  211. <xsl:variable name="tag" select="." />
  212. <xsl:element name="a">
  213. <xsl:attribute name="name">
  214. <xsl:text>n</xsl:text>
  215. <xsl:value-of select="translate($tag, ' ', '')" />
  216. </xsl:attribute>
  217. <xsl:element name="h3"><xsl:value-of select="$tag" /></xsl:element>
  218. </xsl:element>
  219. <xsl:element name="ul">
  220. <!-- loop through all news having this tag -->
  221. <xsl:for-each select="/html/set/news[tags/tag = $tag]">
  222. <xsl:element name="li">
  223. <xsl:element name="a">
  224. <xsl:attribute name="href"><xsl:value-of select="link" /></xsl:attribute>
  225. <xsl:value-of select="title" />
  226. </xsl:element>
  227. </xsl:element>
  228. </xsl:for-each>
  229. </xsl:element>
  230. </xsl:for-each>
  231. </xsl:template>
  232. <!--display dynamic list of tagged events, sorted by tag -->
  233. <xsl:template name="tagged-events">
  234. <xsl:param name="absolute-fsfe-links" />
  235. <!-- loop through all tags (this complex expression loops over each tag once) -->
  236. <xsl:for-each select="/html/set/event/tags/tag[ count( . | key( 'events-tags-by-value', . )[1] ) = 1 ]">
  237. <xsl:sort select="." order="ascending" />
  238. <xsl:variable name="tag" select="." />
  239. <xsl:element name="a">
  240. <xsl:attribute name="name">
  241. <xsl:text>e</xsl:text>
  242. <xsl:value-of select="translate($tag, ' ', '')" />
  243. </xsl:attribute>
  244. <xsl:element name="h3"><xsl:value-of select="$tag" /></xsl:element>
  245. </xsl:element>
  246. <xsl:element name="ul">
  247. <!-- loop through all events having this tag -->
  248. <xsl:for-each select="/html/set/event[tags/tag = $tag]">
  249. <xsl:element name="li">
  250. <xsl:element name="a">
  251. <xsl:attribute name="href">
  252. <xsl:call-template name="event-link">
  253. <xsl:with-param name="absolute-fsfe-links" select="$absolute-fsfe-links" />
  254. </xsl:call-template>
  255. </xsl:attribute>
  256. <xsl:value-of select="title" />
  257. </xsl:element><!--a-->
  258. </xsl:element><!--li-->
  259. </xsl:for-each>
  260. </xsl:element>
  261. </xsl:for-each>
  262. </xsl:template>
  263. </xsl:stylesheet>