]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xsl/ATOM2XHTML.xsl
spit out html -- thanks, a9
[working/Evergreen.git] / Open-ILS / xsl / ATOM2XHTML.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3
4 !! Information About This File: http://opensearch.a9.com/docs/stylesheet.jsp
5
6 Copyright (c) 2005-2006 A9.com, Inc. or its affiliates.
7
8 Author: Michael Fagan, parts by Joel Tesler
9 Changelog:
10         2005-11-28: Updated to work with OpenSearch 1.1 Draft 2 (rather than Draft 1)
11         2005-10-19: Changlog added (unknown update)
12 Description: Converts an OpenSearch feed into XHTML.
13         Can handle
14                 OpenSearch 1.0 and 1.1 Draft 2
15                 RSS 0.9, 0.91, 0.92, 0.93, 1.0, 2.0 and Atom 1.0
16                 (suggested searches using OpenSearch 1.1 Query is not yet handled)
17         Also handles lack of data and errors very well and flexibly. (This is not a strict parser; invalid responses may appear okay)
18         This file should be bunled with a CSS and a Javascript file, the latter is necessary to handle XSLT parsers (e.g. Mozilla-based) that do not support disable-output-escaping
19 Note:
20         Javascript and other potentially malicious code is *not* dealt with
21 To-do list:
22         don't separate authors or categories with a ';' if there's only one of them
23         webMaster (rss) not used due to duplication with managingEditor... really should be able to detect dupes...
24         use dc:source
25         use rating (rss)
26         for link to html version (ideal) for atom make sure alternate link is (x)html (one of list of mime types?)
27         handle common rss/atom extensions (*dc*, geo, vcard, foaf, doap, pheed, media rss, itunes, slash, licenses, etc)
28 -->
29 <xsl:stylesheet version="1.0"
30  xmlns="http://www.w3.org/1999/xhtml"
31  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
32  xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
33  xmlns:opensearchOld="http://a9.com/-/spec/opensearchrss/1.0/"
34  xmlns:atom="http://www.w3.org/2005/Atom"
35  xmlns:rss9="http://my.netscape.com/rdf/simple/0.9/"
36  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
37  xmlns:rss1="http://purl.org/rss/1.0/"
38  xmlns:content="http://purl.org/rss/1.0/modules/content/"
39  xmlns:dc="http://purl.org/dc/elements/1.1/"
40  xmlns:xhtml="http://www.w3.org/1999/xhtml"
41  exclude-result-prefixes="xsl opensearch opensearchOld atom rss9 rdf rss1 content dc xhtml"
42  >
43         <xsl:output omit-xml-declaration="yes" method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="UTF-8" media-type="application/xhtml+xml" />
44         
45         <!-- START SETTINGS -->
46         <!-- text used; change this for translation and also some settings -->
47         <xsl:variable name="t-lang">en-US</xsl:variable> <!-- the ISO 639 code the the language that the text (the texts below) are in -->
48         <!-- next 2 vars are the title and description of error no rss/atom feed found -->
49         <xsl:variable name="t-errortitle">Can't Display Search Results</xsl:variable>
50         <xsl:variable name="t-errordesc">Sorry, there was a problem displaying search results. No valid response was found. Try contacting the owner of this website for assistance.</xsl:variable>
51         <!-- next 4 vars used in <link> tags in the <head> -->
52         <xsl:variable name="t-prevpage">previous page of search results</xsl:variable>
53         <xsl:variable name="t-nextpage">next page of search results</xsl:variable>
54         <xsl:variable name="t-firstpage">first page of search results</xsl:variable>
55         <xsl:variable name="t-lastpage">last page of search results</xsl:variable>
56         <!-- next 3 vars example: "Results 1 to 10 of 35" -->
57         <xsl:variable name="t-results">Results</xsl:variable>
58         <xsl:variable name="t-resultsto">to</xsl:variable>
59         <xsl:variable name="t-resultsof">of</xsl:variable>
60         <xsl:variable name="t-resultstitle">Search Results</xsl:variable> <!-- used in case of absent title -->
61         <xsl:variable name="t-resultsfor">Search Results for</xsl:variable> <!-- used in case of absent title but query is known -->
62         <!-- next 2 vars are text links to previous and next result pages; entitles should be double-escaped as shown -->
63         <xsl:variable name="t-prevlink">&amp;#171; previous</xsl:variable>
64         <xsl:variable name="t-nextlink">next &amp;#187;</xsl:variable>
65         <xsl:variable name="t-nomoreresults">No further results.</xsl:variable> <!-- shown when the page is beyond the last page of results -->
66         <xsl:variable name="t-noresults">Sorry, no results were found.</xsl:variable>
67         <xsl:variable name="t-untitleditem">(untitled)</xsl:variable> <!-- text of untitled items when the title needs to be shown) -->
68         <xsl:variable name="t-entrylink">view full entry</xsl:variable> <!-- text of the link to the full entry (used with <content src="" /> in atom) -->
69         <xsl:variable name="t-authors">by</xsl:variable> <!-- label before one or more author/contributors (eg the 'by' in 'by Joe'); leave blank to not show authors -->
70         <xsl:variable name="t-categories">categories:</xsl:variable> <!-- label before one or more categories; leave blank to not show categories -->
71         <xsl:variable name="t-source">from</xsl:variable> <!-- label of source (e.g. 'from' or 'via' in English); leave blank to not show sources -->
72         <xsl:variable name="t-comments">comments</xsl:variable> <!-- leave blank to not show link to comments -->
73         <xsl:variable name="t-download">download</xsl:variable> <!-- leave this or t-enclosure blank to not show link to enclosures -->
74         <xsl:variable name="t-enclosure">enclosure</xsl:variable> <!-- text of untitled enclosures; leave this or t-download blank to not show link to enclosures -->
75         <xsl:variable name="t-numsep"><xsl:text>,</xsl:text></xsl:variable> <!-- text to separate number of over 3 digits (eg ',' or ' '); leave blank for no separator-->
76         <!-- END SETTINGS -->
77         
78         <xsl:template match="/">
79                 <xsl:comment>For information about the XSLT file that generated this, see http://opensearch.a9.com/docs/stylesheet.jsp</xsl:comment>
80                 <xsl:choose>
81                         <xsl:when test="not(atom:feed | rss/channel | //rss1:item | //rss9:item)">
82                                 <html xml:lang="{$t-lang}" lang="{$t-lang}">
83                                         <head>
84                                                 <title><xsl:value-of select="$t-errortitle" /></title>
85                                                 <meta name="robots" content="noindex,nofollow,noarchive" />
86                                         </head>
87                                         <body><p><xsl:value-of select="$t-errordesc" /></p></body>
88                                 </html>
89                         </xsl:when>
90                         <xsl:otherwise><xsl:apply-templates /></xsl:otherwise>
91                 </xsl:choose>
92         </xsl:template>
93
94         <xsl:template match="atom:feed | rss/channel | rdf:RDF">
95                 <xsl:variable name="language" select="(@xml:lang | language)[1]" />
96                 <html xml:lang="{$language}" lang="{$language}">
97                         <xsl:variable name="query" select="opensearch:Query[@role='request' and @searchTerms][1]/@searchTerms" />
98                         <xsl:variable name="statedtitle" select="(atom:title | title | //rss1:channel/rss1:title | //rss9:channel/rss9:title)[1]" />
99                         <xsl:variable name="title">
100                                 <xsl:choose>
101                                         <xsl:when test="string-length($statedtitle)&gt;0 and (not(string-length($query)&gt;0) or contains($statedtitle, $query))"><xsl:value-of select="$statedtitle" /></xsl:when>
102                                         <xsl:when test="string-length($statedtitle)&gt;0 and string-length($query)&gt;0"><xsl:value-of select="$statedtitle" /> (<xsl:value-of select="$query" />)</xsl:when>
103                                         <xsl:when test="string-length($query)&gt;0"><xsl:value-of select="$t-resultsfor" /> '<xsl:value-of select="$query" />'</xsl:when>
104                                         <xsl:otherwise><xsl:value-of select="$t-resultstitle" /></xsl:otherwise>
105                                 </xsl:choose>
106                         </xsl:variable>
107                         <!-- search stats and rel links -->
108                         <xsl:variable name="items" select="atom:entry | item | //rss1:item | //rss9:item" />
109                         <xsl:variable name="endIndex">
110                                 <xsl:choose>
111                                         <xsl:when test="opensearch:startIndex | opensearchOld:startIndex"><xsl:value-of select="(opensearch:startIndex | opensearchOld:startIndex)[1] + count($items) - 1" /></xsl:when>
112                                         <xsl:otherwise><xsl:value-of select="count($items)" /></xsl:otherwise>
113                                 </xsl:choose>
114                         </xsl:variable>
115                         <xsl:variable name="totalresults"><xsl:if test="(opensearch:totalResults | opensearchOld:totalResults)&gt;=$endIndex"><xsl:value-of select="(opensearch:totalResults | opensearchOld:totalResults)[1]" /></xsl:if></xsl:variable>
116                         <xsl:variable name="navprev"><xsl:if test="atom:link[@rel='previous']/@href and ((opensearch:startIndex&gt;1 or opensearchOld:startIndex&gt;1) or not(opensearch:startIndex or opensearchOld:startIndex))"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(atom:link[@rel='previous']/@href)[1]" /></xsl:call-template></xsl:if></xsl:variable>
117                         <xsl:variable name="navnext"><xsl:if test="atom:link[@rel='next']/@href and (($totalresults&gt;0 and $totalresults&gt;$endIndex) or (not($totalresults&gt;0)))"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="atom:link[@rel='next']/@href" /></xsl:call-template></xsl:if></xsl:variable>
118                         <xsl:variable name="statedStartIndex" select="(opensearch:startIndex | opensearchOld:startIndex)[1]" />
119                         <head>
120                                 <title><xsl:value-of select="$title" /></title>
121                                 <meta name="robots" content="noindex,follow,noarchive" />
122                                 <xsl:if test="atom:icon">
123                                         <xsl:variable name="iconurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="atom:icon[1]" /></xsl:call-template></xsl:variable>
124                                         <link rel="shortcut icon" href="{$iconurl}" />
125                                 </xsl:if>
126                                 <link rel="stylesheet" type="text/css" title="default" media="screen">
127                                         <xsl:attribute name="href"><xsl:value-of select="concat($base_dir,'/os.css')"/></xsl:attribute>
128                                 </link>
129                                 <!-- rel links -->
130                                 <xsl:if test="string-length($navprev)&gt;0"><link rel="previous" href="{$navprev}" title="{$t-prevpage}" /></xsl:if>
131                                 <xsl:if test="string-length($navnext)&gt;0"><link rel="next" href="{$navnext}" title="{$t-nextpage}" /></xsl:if>
132                                 <xsl:if test="atom:link[@rel='first']/@href and ($statedStartIndex&gt;1 or string-length($statedStartIndex)=0)">
133                                         <xsl:variable name="starturl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(atom:link[@rel='first']/@href)[1]" /></xsl:call-template></xsl:variable>
134                                         <link rel="start" title="{$t-firstpage}" href="{$starturl}" />
135                                 </xsl:if>
136                                 <xsl:if test="atom:link[@rel='last']/@href and ($totalresults&gt;$endIndex or string-length($totalresults)=0)">
137                                         <xsl:variable name="endurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(atom:link[@rel='last']/@href)[1]" /></xsl:call-template></xsl:variable>
138                                         <link rel="last" title="{$t-lastpage}" href="{$endurl}"/>
139                                 </xsl:if>
140                                 <xsl:for-each select="atom:link[(@rel='alternate' or @rel='self' or @rel='description') and @href]">
141                                         <xsl:variable name="linkurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="@href" /></xsl:call-template></xsl:variable>
142                                         <link rel="{@rel}" href="{$linkurl}" hreflang="{@hreflang}" title="{@title}" />
143                                 </xsl:for-each>
144                         </head>
145                         <body>
146
147                                 <!-- title section -->
148                                 <div id="header">
149
150
151                                         <xsl:variable name="htmllink" select="(atom:link[@rel='alternate' or not(@rel)]/@href | link | rss1:link)[1]" />
152                                         <h1>
153                                                 <xsl:choose>
154                                                         <xsl:when test="$htmllink">
155                                                                 <xsl:variable name="htmlversion"><xsl:if test="$htmllink"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="$htmllink" /></xsl:call-template></xsl:if></xsl:variable>
156                                                                 <a href="{$htmlversion}"><xsl:value-of select="$title" /></a>
157                                                         </xsl:when>
158                                                         <xsl:otherwise><xsl:value-of select="$title" /></xsl:otherwise>
159                                                 </xsl:choose>
160                                         </h1>
161                                         <xsl:variable name="imgurl" select="(atom:logo | image/url | rss1:image/rss1:url | rss9:image/rss9:url)[1]" />
162                                         <xsl:variable name="absimgurl"><xsl:if test="$imgurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="$imgurl" /></xsl:call-template></xsl:if></xsl:variable>
163                                         <xsl:if test="$absimgurl"><img src="{$absimgurl}" width="{image/width}" height="{image/height}" alt="{image/title}" /></xsl:if>
164                                         <xsl:variable name="subtitle" select="(atom:subtitle | description | //rss1:channel/rss1:description | //rss9:channel/rss9:description)[1]" />
165                                         <xsl:if test="$subtitle and ($subtitle != $title)"><p><xsl:value-of select="$subtitle" /></p></xsl:if>
166                                         <xsl:if test="$t-authors and (managingEditor | atom:author | dc:creator | dc:publisher | atom:contributor | dc:contributor)"><p><xsl:value-of select="concat($t-authors,' ')" /><xsl:apply-templates select="managingEditor | atom:author | dc:creator | dc:publisher | atom:contributor | dc:contributor" /></p></xsl:if>
167                                         <xsl:if test="$t-categories and (atom:category | category)"><xsl:value-of select="concat($t-categories, ' ')" /><p><xsl:apply-templates select="atom:category | category" /></p></xsl:if>
168                                 </div>
169                                 
170                                 <!-- text input: if present in an opensearch feed, this is probably a search box -->
171                                 <xsl:if test="textInput | rss1:textinput"><xsl:apply-templates select="(textInput | rss1:textinput)[1]"><xsl:with-param name="query" select="$query" /></xsl:apply-templates></xsl:if>
172
173                                 <!-- output search results or 'no results' msg -->
174                                 <xsl:choose>
175                                         <xsl:when test="$items">
176                                                 <!-- display the search numbers -->
177                                                 <p>
178                                                         <xsl:value-of select="concat($t-results,' ')" />
179                                                         <xsl:choose>
180                                                                 <xsl:when test="$statedStartIndex&gt;0"><xsl:value-of select="$statedStartIndex" /></xsl:when>
181                                                                 <xsl:otherwise>1</xsl:otherwise>
182                                                         </xsl:choose>
183                                                         <xsl:value-of select="concat(' ', $t-resultsto, ' ')" />
184                                                         <xsl:value-of select="$endIndex" />
185                                                         <xsl:if test="$totalresults&gt;0"><xsl:value-of select="concat(' ', $t-resultsof, ' ')" /><xsl:number value="$totalresults" grouping-size="3" grouping-separator="{$t-numsep}" /></xsl:if>
186                                                 </p>
187                                                 <dl><xsl:apply-templates select="$items" /></dl>
188                                                 <!-- result navigation -->
189                                                 <p id="nav">
190                                                         <xsl:if test="string-length($navprev)&gt;0">
191                                                                 <a class="x-escape" href="{$navprev}" rel="previous"><xsl:value-of select="$t-prevlink" disable-output-escaping="yes" /></a>
192                                                                 <xsl:if test="string-length($navnext)&gt;0"> | </xsl:if>
193                                                         </xsl:if>
194                                                         <xsl:if test="string-length($navnext)&gt;0"><a class="x-escape" href="{$navnext}" rel="next"><xsl:value-of select="$t-nextlink" disable-output-escaping="yes" /></a></xsl:if>
195                                                 </p>
196                                         </xsl:when>
197                                         <xsl:when test="(opensearch:startIndex&gt;1 or opensearchOld&gt;1) and not($totalresults=0)"><xsl:value-of select="$t-nomoreresults" /></xsl:when>
198                                         <xsl:otherwise><p><xsl:value-of select="$t-noresults" /></p></xsl:otherwise>
199                                 </xsl:choose>
200
201                                 <!-- display the copyright -->
202                                 <xsl:variable name="rights" select="(atom:rights[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml'] | copyright | dc:rights)[1]" />
203                                 <div id="footer">
204                                         <xsl:if test="$rights"><p><xsl:call-template name="showtext"><xsl:with-param name="node" select="$rights" /></xsl:call-template></p></xsl:if>
205                                         <p><small>This XSLT is &#169; <a href="http://a9.com/">A9.com, Inc</a>; see <a href="http://opensearch.a9.com/docs/stylesheet.jsp">full details</a>.</small></p>
206                                 </div>
207
208                         </body>
209                 </html>
210         </xsl:template>
211         
212         <xsl:template match="textInput | rss1:textinput">
213                 <xsl:param name="query" />
214                 <xsl:if test="(name | rss1:name) and (link | rss1:link)">
215                         <xsl:variable name="formaction"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(link | rss1:link)[1]" /></xsl:call-template></xsl:variable>
216                         <form method="get" action="{$formaction}">
217                                 <input type="text" name="{name | rss1:name}" value="{$query}" />
218                                 <xsl:choose>
219                                         <xsl:when test="title | rss1:title"><input type="submit" value="{title | rss1:title}" /></xsl:when>
220                                         <xsl:otherwise><input type="submit" /></xsl:otherwise>
221                                 </xsl:choose>
222                                 <xsl:if test="description | rss1:description"><p><xsl:value-of select="(description | rss1:description)[1]" /></p></xsl:if>
223                         </form>
224                 </xsl:if>
225         </xsl:template>
226
227         <xsl:template match="atom:entry | item | //rss1:item | //rss9:item"> <!-- match="" must match the select="" earlier on -->
228                 <xsl:variable name="url"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(atom:link[not(@rel) or @rel='alternate' or @rel='']/@href | link | guid[@isPermaLink='true'] | rss1:link | rss9:link)[1]" /></xsl:call-template></xsl:variable>
229                 <!-- item title -->
230                 <dt>
231                         <xsl:choose>
232                                 <xsl:when test="string-length($url)&gt;0">
233                                         <a href="{$url}">
234                                                 <xsl:choose>
235                                                         <xsl:when test="atom:title | title | rss1:title | rss9:title"><xsl:call-template name="showtext"><xsl:with-param name="node" select="(atom:title | title | rss1:title | rss9:title)[1]" /></xsl:call-template></xsl:when>
236                                                         <xsl:otherwise><xsl:value-of select="$t-untitleditem" /></xsl:otherwise>
237                                                 </xsl:choose>
238                                         </a>
239                                 </xsl:when>
240                                 <xsl:otherwise>
241                                         <strong>
242                                                 <xsl:choose>
243                                                         <xsl:when test="atom:title | title | rss1:title | rss9:title"><xsl:call-template name="showtext"><xsl:with-param name="node" select="(atom:title | title | rss1:title | rss9:title)[1]" /></xsl:call-template></xsl:when>
244                                                         <xsl:otherwise><xsl:value-of select="$t-untitleditem" /></xsl:otherwise>
245                                                 </xsl:choose>
246                                         </strong>
247                                 </xsl:otherwise>
248                         </xsl:choose>
249                         <!-- item authors -->
250                         <xsl:if test="$t-authors and (author | atom:author | atom:contributor | dc:creator | dc:publisher | dc:contributor)">
251                                 <xsl:value-of select="concat(' ', $t-authors, ' ')" />
252                                 <xsl:apply-templates select="author | atom:author | atom:contributor | dc:creator | dc:publisher | dc:contributor" />
253                         </xsl:if>
254                 </dt>
255                 <!-- item description -->
256                 <xsl:if test="atom:content[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml'] | content:encoded | description | rss1:description | rss9:description | atom:summary[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml']">
257                         <dd class="desc">
258                                 <xsl:choose>
259                                         <xsl:when test="atom:content[(not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml') and not(@src)] | content:encoded"><xsl:call-template name="showtext"><xsl:with-param name="node" select="atom:content[(not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml') and not(@src)] | content:encoded" /></xsl:call-template></xsl:when>
260                                         <xsl:when test="description | rss1:description | rss9:description | atom:summary[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml']"><xsl:call-template name="showtext"><xsl:with-param name="node" select="description | rss1:description | rss9:description | atom:summary[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml']" /></xsl:call-template></xsl:when>
261                                 </xsl:choose>
262                                 <xsl:if test="atom:content/@src">
263                                         <xsl:if test="atom:summary"><br /></xsl:if>
264                                         <a>
265                                                 <xsl:attribute name="href"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="atom:content/@src" /></xsl:call-template></xsl:attribute>
266                                                 <xsl:value-of select="$t-entrylink" />
267                                         </a>
268                                 </xsl:if>
269                         </dd>
270                 </xsl:if>
271                 <!-- item categories -->
272                 <xsl:if test="$t-categories and (atom:category | category)"><dd><xsl:value-of select="concat($t-categories, ' ')" /><xsl:apply-templates select="atom:category | category" /></dd></xsl:if>
273                 <!-- item source -->
274                 <xsl:if test="string-length($t-source)&gt;0">
275                         <xsl:variable name="maybesourceurl" select="(atom:source/link[@rel='alternate']/@href | source/@url)[1]" />
276                         <xsl:variable name="sourceurl"><xsl:if test="$maybesourceurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="$maybesourceurl" /></xsl:call-template></xsl:if></xsl:variable>
277                         <xsl:variable name="maybesourcename">
278                                 <xsl:choose>
279                                         <xsl:when test="atom:source/title[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml']"><xsl:value-of select="atom:source/title[@type='' or @type='text' or @type='html' or @type='xhtml'][1]" /></xsl:when>
280                                         <xsl:when test="string-length(source)&gt;0"><xsl:value-of select="source[1]" /></xsl:when>
281                                         </xsl:choose>
282                         </xsl:variable>
283                         <xsl:if test="string-length($sourceurl)&gt;0 or string-length($maybesourcename)&gt;0">
284                                 <dd>
285                                         <xsl:value-of select="concat($t-source,' ')" />
286                                         <xsl:variable name="sourcename">
287                                                 <xsl:choose>
288                                                         <xsl:when test="$maybesourcename"><xsl:value-of select="$maybesourcename" /></xsl:when>
289                                                         <xsl:otherwise><xsl:value-of select="$sourceurl" /></xsl:otherwise>
290                                                 </xsl:choose>
291                                         </xsl:variable>
292                                         <xsl:choose>
293                                                 <xsl:when test="$sourceurl"><a href="{$sourceurl}"><xsl:value-of select="$sourcename" /></a></xsl:when>
294                                                 <xsl:otherwise><xsl:value-of select="$sourcename" /></xsl:otherwise>
295                                         </xsl:choose>
296                                 </dd>
297                         </xsl:if>
298                 </xsl:if>
299                 <!-- item comments -->
300                 <xsl:if test="comments and string-length($t-comments)&gt;0">
301                         <xsl:variable name="commentsurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="comments[1]" /></xsl:call-template></xsl:variable>
302                         <dd><a href="{$commentsurl}"><xsl:value-of select="$t-comments" /></a></dd>
303                 </xsl:if>
304                 <!-- item enclosure -->
305                 <xsl:if test="(atom:link[@rel='enclosure']/@href | enclosure/@url) and string-length($t-download)&gt;0 and string-length($t-enclosure)&gt;0"><dd><xsl:apply-templates select="atom:link[@rel='enclosure'] | enclosure" /></dd></xsl:if>
306                 <!-- item rights -->
307                 <xsl:variable name="itemrights" select="atom:rights[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml'][1]" />
308                 <xsl:if test="$itemrights"><dd class="rights"><xsl:call-template name="showtext"><xsl:with-param name="node" select="$itemrights" /></xsl:call-template></dd></xsl:if>
309                 <!-- item url -->
310                 <xsl:if test="string-length($url)&gt;0">
311                         <dd class="url">
312                                 <xsl:choose>
313                                         <xsl:when test="string-length(substring-after($url, 'http://'))&gt;100"><xsl:value-of select="concat(substring(substring-after($url, 'http://'),1,100),'&#8230;')" /></xsl:when>
314                                         <xsl:otherwise><xsl:value-of select="substring-after($url, 'http://')" /></xsl:otherwise>
315                                 </xsl:choose>
316                         </dd>
317                 </xsl:if>
318         </xsl:template>
319
320         <xsl:template match="atom:link[@rel='enclosure'] | enclosure">
321                 <xsl:variable name="encurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(@href | @url)[1]" /></xsl:call-template></xsl:variable>
322                 <xsl:value-of select="concat($t-download, ' ')" />
323                 <a href="{$encurl}">
324                         <xsl:choose>
325                                 <xsl:when test="@title"><xsl:value-of select="@title" /></xsl:when>
326                                 <xsl:otherwise><xsl:value-of select="$t-enclosure" /></xsl:otherwise>
327                         </xsl:choose>
328                 </a>
329                 <xsl:if test="@type"> (<xsl:value-of select="@type" />)</xsl:if>
330         </xsl:template>
331
332         <xsl:template match="atom:category | category">
333                 <xsl:variable name="name">
334                         <xsl:choose>
335                                 <xsl:when test="not(namespace-uri())"><xsl:value-of select="." /></xsl:when>
336                                 <xsl:when test="@label"><xsl:value-of select="@label" /></xsl:when>
337                                 <xsl:when test="@term"><xsl:value-of select="@term" /></xsl:when>
338                         </xsl:choose>
339                 </xsl:variable>
340                 <xsl:if test="string-length($name)&gt;0">
341                         <xsl:variable name="category">
342                                 <xsl:choose>
343                                         <xsl:when test="not(namespace-uri())"><xsl:value-of select="." /></xsl:when>
344                                         <xsl:otherwise><xsl:value-of select="@term" /></xsl:otherwise>
345                                 </xsl:choose>
346                         </xsl:variable>
347                         <xsl:variable name="maybeurl" select="(@domain | @scheme)[1]" />
348                         <xsl:variable name="url">
349                                 <xsl:if test="starts-with($maybeurl, 'http')">
350                                         <xsl:value-of select="concat($maybeurl, '#', $category)" />
351                                 </xsl:if>
352                         </xsl:variable>
353                         <xsl:choose>
354                                 <xsl:when test="string-length($url)&gt;0"><a href="{$url}"><xsl:value-of select="$name" /></a></xsl:when>
355                                 <xsl:otherwise><xsl:value-of select="$name" /></xsl:otherwise>
356                         </xsl:choose>
357                         <xsl:text>; </xsl:text>
358                 </xsl:if>
359         </xsl:template>
360         
361         <!-- outputs a 'person' (next 4 templates) -->
362         <xsl:template match="dc:creator | dc:publisher | dc:contributor">
363                 <xsl:call-template name="person"><xsl:with-param name="name" select="." /></xsl:call-template>
364         </xsl:template>
365         <xsl:template match="managingEditor | webMaster | author">
366                 <xsl:call-template name="person">
367                         <xsl:with-param name="email" select="substring-before(concat(normalize-space(.),' '), ' ')" />
368                         <xsl:with-param name="name"><xsl:if test="substring-after(., '(')"><xsl:value-of select="normalize-space(substring-before(substring-after(., '('), ')'))" /></xsl:if></xsl:with-param>
369                 </xsl:call-template>
370         </xsl:template>
371         <xsl:template match="atom:author | atom:contributor">
372                 <xsl:call-template name="person">
373                         <xsl:with-param name="link"><xsl:if test="atom:uri"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="atom:uri" /></xsl:call-template></xsl:if></xsl:with-param>
374                         <xsl:with-param name="email" select="atom:email" />
375                         <xsl:with-param name="name" select="atom:name" />
376                 </xsl:call-template>
377         </xsl:template>
378         <xsl:template name="person">
379                 <xsl:param name="email" />
380                 <xsl:param name="link" />
381                 <xsl:param name="name" />
382                 <xsl:variable name="showname">
383                         <xsl:choose>
384                                 <xsl:when test="string-length($name)&gt;0"><xsl:value-of select="$name" /></xsl:when>
385                                 <xsl:when test="string-length($email)&gt;0"><xsl:value-of select="$email" /></xsl:when>
386                                 <xsl:otherwise><xsl:value-of select="$link" /></xsl:otherwise>
387                         </xsl:choose>
388                 </xsl:variable>
389                 <xsl:variable name="showlink">
390                         <xsl:choose>
391                                 <xsl:when test="string-length($link)"><xsl:value-of select="$link" /></xsl:when>
392                                 <xsl:when test="string-length($email)">mailto:<xsl:value-of select="$email" /></xsl:when>
393                         </xsl:choose>
394                 </xsl:variable>
395                 <xsl:if test="string-length($showname)&gt;0">
396                         <xsl:choose>
397                                 <xsl:when test="string-length($showlink)&gt;0"><a href="{$showlink}"><xsl:value-of select="$showname" /></a></xsl:when>
398                                 <xsl:otherwise><xsl:value-of select="$showname" /></xsl:otherwise>
399                         </xsl:choose>
400                         <xsl:text>; </xsl:text>
401                 </xsl:if>
402         </xsl:template>
403         
404         <!-- outputs text/(x)html; based on code from jtesler -->
405         <xsl:template name="showtext">
406                 <xsl:param name="node" />
407                 <xsl:choose>
408                         <xsl:when test="name($node)='description' or $node/@type='html'"><div class="x-escape"><xsl:value-of select="$node" disable-output-escaping="yes" /></div></xsl:when>
409                         <xsl:when test="$node/@type='xhtml'"><xsl:apply-templates select="$node/xhtml:div" mode="stripXhtml" /></xsl:when>
410                         <xsl:otherwise><xsl:value-of select="$node" /></xsl:otherwise>
411                 </xsl:choose>
412         </xsl:template>
413         <!-- These templates are used for outputting the xhtml output.  We need to
414         Strip xhtml: from all the nodes.  We must also convert any href and src
415         attributes from relative to absolute if there is an xml:base -->
416         <xsl:template match="xhtml:*" mode="stripXhtml">
417                 <xsl:element name="{local-name()}">
418                         <xsl:if test="@href"><xsl:attribute name="href"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="@href"/></xsl:call-template></xsl:attribute></xsl:if>
419                         <xsl:if test="@src"><xsl:attribute name="src"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="@src"/></xsl:call-template></xsl:attribute></xsl:if>
420                         <xsl:apply-templates select="@* | node()" mode="stripXhtml" />
421                 </xsl:element>
422         </xsl:template>
423         <xsl:template match="node() | @*" mode="stripXhtml"><xsl:copy><xsl:apply-templates select="@* | node()" mode="stripXhtml" /></xsl:copy></xsl:template>
424         <!-- Since we already processed href and src nodes up above, don't process them again here -->
425         <xsl:template match="@href | @src" mode="stripXhtml" priority="1" />
426         
427         <!-- returns absolute links, given absolute ones or relative ones with base ones -->
428         <xsl:template name="resolvelink">
429                 <xsl:param name="url" />
430                 <xsl:param name="node" select="$url" />
431                 <xsl:choose>
432                         <xsl:when test="(contains($url,':') and (not(contains($url,'/')) or contains(substring-before($url,':'), substring-before($url,':')))) or not($url)"><xsl:value-of select="$url" /></xsl:when><!-- url is absolute already -->
433                         <xsl:otherwise>
434                                 <xsl:variable name="basenode" select="($node/ancestor-or-self::*[@xml:base])[last()]" />
435                                 <xsl:variable name="base">
436                                                 <xsl:call-template name="resolvelink">
437                                                 <xsl:with-param name="url" select="$basenode/@xml:base" />
438                                                 <xsl:with-param name="node" select="($basenode/ancestor::*[@xml:base])[last()]" />
439                                         </xsl:call-template>
440                                 </xsl:variable>
441                                 <xsl:variable name="protocol"><xsl:if test="contains($base, '://')"><xsl:value-of select="concat(substring-before($base, '://'), '://')" /></xsl:if></xsl:variable>
442                                 <xsl:variable name="basenoprot"><xsl:choose><xsl:when test="string-length($protocol)"><xsl:value-of select="substring-after($base, '://')" /></xsl:when><xsl:otherwise><xsl:value-of select="$base" /></xsl:otherwise></xsl:choose></xsl:variable>
443                                 <xsl:variable name="trailingslash"><xsl:if test="substring($basenoprot,string-length($basenoprot),1)='/'">true</xsl:if></xsl:variable>
444                                 <xsl:variable name="usebase">
445                                         <xsl:value-of select="$protocol" />
446                                         <xsl:choose>
447                                                 <xsl:when test="not(string-length($trailingslash)) and not(contains($basenoprot, '/'))"><xsl:value-of select="$basenoprot" />/</xsl:when>
448                                                 <xsl:when test="not(string-length($trailingslash)) and contains($basenoprot, '/') and $url != '' and not(starts-with($url, '#')) and not(starts-with($url, '?'))">
449                                                         <xsl:call-template name="uponelevel">
450                                                                 <xsl:with-param name="url" select="$basenoprot" />
451                                                         </xsl:call-template>
452                                                 </xsl:when>
453                                                 <xsl:otherwise><xsl:value-of select="$basenoprot" /></xsl:otherwise>
454                                         </xsl:choose>
455                                 </xsl:variable>
456                                 <xsl:choose>
457                                         <xsl:when test="starts-with($url,'/')"><xsl:value-of select="concat(substring-before($base, '://'), '://', substring-before(substring-after($usebase, '://'), '/'), $url)" /></xsl:when>
458                                         <xsl:when test="starts-with($url,'../')">
459                                                 <xsl:call-template name="resolvelink">
460                                                         <xsl:with-param name="url" select="substring-after($url, '../')" />
461                                                         <xsl:with-param name="base">
462                                                                 <xsl:value-of select="concat(substring-before($base,'://'), '://')" />
463                                                                 <xsl:call-template name="uponelevel"><xsl:with-param name="url" select="substring-after(substring($usebase, 0, string-length($usebase)-1), '://')" /></xsl:call-template>
464                                                         </xsl:with-param>
465                                                 </xsl:call-template>
466                                         </xsl:when>
467                                         <xsl:otherwise>
468                                                 <xsl:variable name="useurl">
469                                                         <xsl:choose>
470                                                                 <xsl:when test="starts-with($url, './')"><xsl:value-of select="substring-after($url, './')" /></xsl:when>
471                                                                 <xsl:otherwise><xsl:value-of select="$url" /></xsl:otherwise>
472                                                         </xsl:choose>
473                                                 </xsl:variable>
474                                                 <xsl:value-of select="concat($usebase, $useurl)" />
475                                         </xsl:otherwise>
476                                 </xsl:choose>
477                         </xsl:otherwise>
478                 </xsl:choose>
479         </xsl:template>
480         <xsl:template name="uponelevel">
481                 <xsl:param name="url" /> <!-- url looks like sub.domain.com/folder/two/three -->
482                 <xsl:variable name="firstpart" select="substring-before($url, '/')" />
483                 <xsl:variable name="afterslash" select="substring-after($url, '/')" />
484                 <xsl:variable name="secondpart"><xsl:if test="contains($afterslash, '/')"><xsl:call-template name="uponelevel"><xsl:with-param name="url" select="$afterslash" /></xsl:call-template></xsl:if></xsl:variable>
485                 <xsl:value-of select="concat($firstpart, '/', $secondpart)" />
486         </xsl:template>
487
488 </xsl:stylesheet>