rss.xsl 4.5 KB

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