warbo-utilities: b928580c8c5920c2b08fb5690356c46d007e5d3f
1: <?xml version="1.0" encoding="UTF-8" ?>
2: <!-- Released under CC lincense http://creativecommons.org/licenses/by/2.5/ -->
3: <!-- Feeds generated using this stylesheet (or it's derivatives) must put http://atom.geekhood.net in <generator> element -->
4: <!-- This is a derivative in that it was modified by Gene McCulley to support his blog. -->
5: <x:stylesheet version="1.0"
6: exclude-result-prefixes="atom xhtml"
7: xmlns:x="http://www.w3.org/1999/XSL/Transform"
8: xmlns:atom="http://www.w3.org/2005/Atom"
9: xmlns:dc="http://purl.org/dc/elements/1.1/"
10: xmlns:date="http://exslt.org/dates-and-times"
11: xmlns:xhtml="http://www.w3.org/1999/xhtml">
12: <x:output encoding="UTF-8" indent="yes" method="xml" />
13:
14: <x:template match="/atom:feed">
15: <rss version="2.0">
16: <channel>
17: <generator><x:if test="atom:generator"><x:apply-templates select="atom:generator" mode="gen"/> + </x:if>Atom 1.0 EXSLT Transform v1.1 (http://atom.geekhood.net/)</generator>
18: <x:if test="//@xml:lang">
19: <language><x:value-of select="//@xml:lang[1]" /></language>
20: </x:if>
21:
22: <description>
23: <x:choose>
24: <x:when test="atom:subtitle"><x:apply-templates select="atom:subtitle" mode="asHTML"/></x:when>
25: <x:otherwise>
26: <!-- this sucks -->
27: <x:apply-templates select="atom:title" mode="asHTML"/> (converted from Atom 1.0)
28: </x:otherwise>
29: </x:choose>
30: </description>
31:
32: <x:choose>
33: <x:when test="atom:logo"><image><x:apply-templates select="atom:logo" mode="image"/></image></x:when>
34: <x:when test="atom:icon"><image><x:apply-templates select="atom:icon" mode="image"/></image></x:when>
35: </x:choose>
36:
37: <x:apply-templates />
38: </channel>
39: </rss>
40: </x:template>
41:
42:
43: <!-- simple losless conversions -->
44: <x:template match="atom:contributor">
45: <dc:contributor><x:call-template name="person" /></dc:contributor>
46: </x:template>
47:
48: <x:template match="atom:title">
49: <title><x:call-template name="asHTML" /></title>
50: </x:template>
51:
52: <x:template match="atom:generator"/>
53: <x:template match="atom:generator" mode="gen">
54: <x:apply-templates mode="asText"/> <x:if test="@version"> v<x:value-of select="@version"/></x:if> <x:if test="@uri"> (<x:value-of select="@uri"/>)</x:if>
55: </x:template>
56:
57: <x:template match="atom:entry/atom:published"><pubDate><x:call-template name="rfc822Date"><x:with-param name="isoDate" select="."/></x:call-template></pubDate></x:template>
58: <x:template match="atom:entry/atom:updated"><pubDate><x:call-template name="rfc822Date"><x:with-param name="isoDate" select="."/></x:call-template></pubDate></x:template>
59: <x:template match="atom:feed/atom:updated"><pubDate><x:call-template name="rfc822Date"><x:with-param name="isoDate" select="."/></x:call-template></pubDate></x:template>
60:
61: <x:template match="atom:rights"><copyright><x:apply-templates /></copyright></x:template>
62:
63: <x:template match="atom:link[not(@rel) or @rel='alternate']"><link><x:value-of select="@href"/></link></x:template>
64:
65: <x:template match="atom:link[@rel='enclosure']"><enclosure url="{@href}" type="{@type}" length="{@length}"/></x:template>
66:
67: <x:template match="atom:entry/atom:id">
68: <guid>
69: <x:if test="not(. = ../atom:link[@rel='alternate']/@href) and not(. = ../atom:link[@rel='permalink']/@href) and not(. = ../atom:link[not(@rel)]/@href)">
70: <x:attribute name="isPermaLink">false</x:attribute>
71: </x:if>
72: <x:apply-templates />
73: </guid>
74: </x:template>
75:
76: <!-- dodgy conversions -->
77: <x:template match="atom:icon|atom:logo"/><!-- merged into rss:image -->
78: <x:template match="atom:icon|atom:logo" mode="image">
79: <url><x:value-of select="."/></url>
80: <x:if test="../atom:title"><title><x:apply-templates select="../atom:title" mode="asText" /></title></x:if>
81: <x:if test="../atom:link[not(@rel) or @rel='alternate']"><link><x:value-of select="../atom:link[not(@rel) or @rel='alternate'][1]/@href"/></link></x:if>
82: </x:template>
83:
84: <x:template name="person">
85: <x:choose>
86: <x:when test="atom:email"><x:value-of select="atom:email"/></x:when>
87: <x:when test="/atom:feed/atom:author[./atom:email][1]/atom:email"><x:value-of select="/atom:feed/atom:author[./atom:email][1]/atom:email"/></x:when>
88: </x:choose>
89: (<x:value-of select="atom:name"/><x:if test="@uri"> <x:value-of select="uri"/></x:if>)
90: </x:template>
91:
92: <x:template match="atom:entry/atom:author[not(contains(./atom:email,'webmaster'))][1]">
93: <author>
94: <x:call-template name="person" />
95: </author>
96: </x:template>
97:
98: <x:template match="atom:feed/atom:author[not(contains(./atom:email,'webmaster'))][1]">
99: <managingEditor>
100: <x:call-template name="person" />
101: </managingEditor>
102: </x:template>
103:
104: <x:template match="atom:author[contains(./atom:email,'webmaster')][1]">
105: <webMaster>
106: <x:call-template name="person" />
107: </webMaster>
108: </x:template>
109:
110: <x:template match="atom:subtitle"/>
111:
112: <x:template match="atom:source">
113: <source url="{atom:link[@rel='self']}"><x:apply-templates select="atom:title" mode="asText"/></source>
114: </x:template>
115:
116: <!-- lossy conversion -->
117: <x:template match="atom:feed/atom:id"/>
118:
119: <x:template match="atom:feed/atom:link[@rel='self']"><x:comment> source: <x:value-of select="@href"/><x:text> </x:text></x:comment></x:template>
120:
121: <x:template match="atom:category"><!-- label gets lost -->
122: <category>
123: <x:if test="@scheme">
124: <x:attribute name="domain"><x:value-of select="@scheme"/></x:attribute>
125: </x:if>
126: <x:value-of select="@term"/>
127: <x:if test="@label and not(@label = @term)"><x:comment><x:value-of select="@label"/></x:comment></x:if>
128: </category>
129: </x:template>
130:
131:
132: <!-- entry -->
133: <x:template match="atom:summary|atom:content"/>
134:
135: <x:template match="atom:entry">
136: <item>
137: <x:choose>
138: <x:when test="atom:summary"><description><x:apply-templates select="atom:summary" mode="asHTML"/> <x:if test="atom:content"> (...)</x:if></description></x:when>
139: <x:when test="atom:content"><description><x:apply-templates select="atom:content" mode="asHTML"/></description></x:when>
140: </x:choose>
141: <x:apply-templates/>
142: <x:if test="not(atom:source) and /atom:feed/atom:link[@rel='self']">
143: <source url="{/atom:feed/atom:link[@rel='self']/@href}">
144: <x:choose>
145: <x:when test="/atom:feed/atom:link[@rel='self' and @title]"><x:value-of select="/atom:feed/atom:link[@rel='self']/@title"/></x:when>
146: <x:otherwise><x:apply-templates select="/atom:feed/atom:title" mode="asText"/></x:otherwise>
147: </x:choose>
148: </source>
149: </x:if>
150: <x:apply-templates select="atom:source/atom:category"/>
151: <x:if test="not(atom:copyright)"><x:apply-templates select="atom:source/atom:copyright"/></x:if>
152: <x:if test="not(atom:author)"><x:apply-templates select="atom:source/atom:author"/></x:if>
153: <x:if test="not(atom:contributor)"><x:apply-templates select="atom:source/atom:contributor"/></x:if>
154: <x:if test="not(atom:updated)"><x:apply-templates select="atom:source/atom:updated"/></x:if>
155: </item>
156: </x:template>
157:
158:
159: <!-- santas little helpers -->
160: <x:template match="*" mode="asHTML"><x:call-template name="asHTML"/></x:template>
161: <x:template name="asHTML">
162: <x:choose>
163: <x:when test="@type='xhtml'">
164: <x:apply-templates select="xhtml:div" mode="xhtml2html" />
165: </x:when>
166: <x:when test="@type='html'"><x:value-of select="." /></x:when>
167: <x:otherwise>
168: <x:text disable-output-escaping="yes"><![CDATA[</x:text>
169: <x:value-of select="." />
170: <x:text disable-output-escaping="yes">]]></x:text>
171: </x:otherwise>
172: </x:choose>
173: </x:template>
174:
175: <x:template match="*[@type='html' or @type='text/html']" mode="asText">
176: <x:call-template name="removeHtml"><x:with-param name="text" select="."/></x:call-template>
177: </x:template>
178:
179: <x:template match="*" mode="asText">
180: <x:value-of select="."/>
181: </x:template>
182:
183:
184: <!-- html 2 text (primitive method) -->
185: <x:template name="removeHtml">
186: <x:param name="text"/>
187: <x:choose>
188: <x:when test="contains($text, '<') and contains(substring-after($text, '<'),'>')">
189: <x:value-of select="substring-before($text, '<')"/>
190: <x:call-template name="removeHtml">
191: <x:with-param name="text" select="substring-after(substring-after($text,'<'),'>')"/>
192: </x:call-template>
193: </x:when>
194: <x:otherwise>
195: <x:value-of select="$text"/>
196: </x:otherwise>
197: </x:choose>
198: </x:template>
199:
200:
201: <!-- xhtml 2 html -->
202: <x:template match="xhtml:img|xhtml:br|xhtml:hr|xhtml:input|xhtml:col|xhtml:area|xhtml:input|xhtml:link|xhtml:meta|xhtml:param" mode="xhtml2html">
203: <<x:value-of select="local-name(.)"/><x:apply-templates select="@*" mode="xhtml2html"/>><x:apply-templates mode="xhtml2html"/>
204: </x:template>
205:
206: <x:template match='xhtml:*' mode="xhtml2html">
207: <<x:value-of select="local-name(.)"/><x:apply-templates select="@*" mode="xhtml2html"/>><x:apply-templates mode="xhtml2html"/></<x:value-of select="local-name(.)"/>>
208: </x:template>
209:
210: <x:template match='@*' mode="xhtml2html">
211: <x:text> </x:text><x:value-of select="local-name(.)"/>="<x:value-of select="."/>"</x:template>
212:
213: <x:template match='node()' mode="xhtml2html">
214: <x:choose>
215: <x:when test="contains(.,'&') or contains(.,'<')">
216: <x:text disable-output-escaping="yes"><![CDATA[</x:text>
217: <x:value-of select="." />
218: <x:text disable-output-escaping="yes">]]></x:text>
219: </x:when>
220: <x:otherwise>
221: <x:value-of select="."/>
222: </x:otherwise>
223: </x:choose>
224: </x:template>
225:
226: <!-- copy extensions -->
227: <x:template match='*'>
228: <x:comment>Unknown element <x:value-of select="local-name(.)"/></x:comment>
229: <x:copy>
230: <x:copy-of select='node()|@*'/>
231: </x:copy>
232: </x:template>
233:
234: <!-- Converts a date in ISO 8601 format into a date in RFC 822 format -->
235: <x:template name="rfc822Date">
236: <x:param name="isoDate"/>
237:
238: <x:value-of select="date:day-abbreviation($isoDate)"/>, <x:value-of select="format-number(date:day-in-month($isoDate), '00')"/><x:text> </x:text>
239: <x:value-of select="date:month-abbreviation($isoDate)"/><x:text> </x:text>
240: <x:value-of select="date:year($isoDate)"/><x:text> </x:text>
241:
242: <!-- the timezone offset is currently hardcoded needs to be fixed -->
243: <x:value-of select="format-number(date:hour-in-day($isoDate), '00')"/>:<x:value-of select="format-number(date:minute-in-hour($isoDate), '00')"/>:<x:value-of select="format-number(date:second-in-minute($isoDate), '00')"/> GMT
244: </x:template>
245:
246: </x:stylesheet>
Generated by git2html.