]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xsl/ATOM2XHTML.xsl
basic searching within the opensearch results
[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="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" encoding="UTF-8" media-type="text/html" />
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">Subjects:</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         <!-- END SETTINGS -->
76
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
119                         <xsl:variable name="statedStartIndex" select="(opensearch:startIndex | opensearchOld:startIndex)[1]" />
120                         <head>
121                                 <title><xsl:value-of select="$title" /></title>
122                                 <meta name="robots" content="noindex,follow,noarchive" />
123                                 <xsl:if test="atom:icon">
124                                         <xsl:variable name="iconurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="atom:icon[1]" /></xsl:call-template></xsl:variable>
125                                         <link rel="shortcut icon" href="{$iconurl}" />
126                                 </xsl:if>
127                                 <link rel="stylesheet" type="text/css" title="default" media="screen">
128                                         <xsl:attribute name="href"><xsl:value-of select="concat($base_dir,'os.css')"/></xsl:attribute>
129                                 </link>
130                                 <!-- rel links -->
131
132                                 <xsl:for-each select="atom:link[@rel='unapi' and string-length(@href)&gt;0]">
133                                         <link rel="meta" title="unAPI" type="application/xml">
134                                                 <xsl:attribute name='href'>
135                                                         <xsl:value-of select="./@href"/>
136                                                 </xsl:attribute>
137                                         </link>
138                                 </xsl:for-each>
139
140                                 <xsl:if test="string-length($navprev)&gt;0"><link rel="previous" href="{$navprev}" title="{$t-prevpage}" /></xsl:if>
141                                 <xsl:if test="string-length($navnext)&gt;0"><link rel="next" href="{$navnext}" title="{$t-nextpage}" /></xsl:if>
142                                 <xsl:if test="atom:link[@rel='first']/@href and ($statedStartIndex&gt;1 or string-length($statedStartIndex)=0)">
143                                         <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>
144                                         <link rel="start" title="{$t-firstpage}" href="{$starturl}" />
145                                 </xsl:if>
146                                 <xsl:if test="atom:link[@rel='last']/@href and ($totalresults&gt;$endIndex or string-length($totalresults)=0)">
147                                         <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>
148                                         <link rel="last" title="{$t-lastpage}" href="{$endurl}"/>
149                                 </xsl:if>
150                                 <xsl:for-each select="atom:link[(@rel='alternate' or @rel='self' or @rel='description') and @href]">
151                                         <xsl:variable name="linkurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="@href" /></xsl:call-template></xsl:variable>
152                                         <link rel="{@rel}" href="{$linkurl}" hreflang="{@hreflang}" title="{@title}" />
153                                 </xsl:for-each>
154                         </head>
155                         <body>
156
157                                 <!-- title section -->
158                                 <div id="header">
159
160
161                                         <xsl:variable name="htmllink" select="(atom:link[@rel='alternate' or not(@rel)]/@href | link | rss1:link)[1]" />
162                                         <h1>
163                                                 <xsl:choose>
164                                                         <xsl:when test="$htmllink">
165                                                                 <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>
166                                                                 <a href="{$htmlversion}"><xsl:value-of select="$title" /></a>
167                                                         </xsl:when>
168                                                         <xsl:otherwise><xsl:value-of select="$title" /></xsl:otherwise>
169                                                 </xsl:choose>
170                                         </h1>
171                                         <xsl:variable name="imgurl" select="(atom:logo | image/url | rss1:image/rss1:url | rss9:image/rss9:url)[1]" />
172                                         <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>
173                                         <xsl:if test="$absimgurl"><img src="{$absimgurl}" width="{image/width}" height="{image/height}" alt="{image/title}" /></xsl:if>
174                                         <xsl:variable name="subtitle" select="(atom:subtitle | description | //rss1:channel/rss1:description | //rss9:channel/rss9:description)[1]" />
175                                         <xsl:if test="$subtitle and ($subtitle != $title)"><p><xsl:value-of select="$subtitle" /></p></xsl:if>
176                                         <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>
177                                         <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>
178                                 </div>
179
180                                 <div id="searchdiv">
181                                         <b>Search:</b>
182                                         <form method="GET">
183                                                 <xsl:attribute name="action"><xsl:value-of select="concat($base_dir, 'opensearch/1.1/', $lib, '/html/keyword')" /></xsl:attribute>
184                                                 <input class="searchbox" type="text" name="searchTerms" value="keywords" onfocus="this.value='';"/>
185                                         </form>
186                                         <form method="GET">
187                                                 <xsl:attribute name="action"><xsl:value-of select="concat($base_dir, 'opensearch/1.1/', $lib, '/html/title')" /></xsl:attribute>
188                                                 <input class="searchbox" type="text" name="searchTerms" value="titles" onfocus="this.value='';"/>
189                                         </form>
190                                         <form method="GET">
191                                                 <xsl:attribute name="action"><xsl:value-of select="concat($base_dir, 'opensearch/1.1/', $lib, '/html/author')" /></xsl:attribute>
192                                                 <input class="searchbox" type="text" name="searchTerms" value="authors" onfocus="this.value='';"/>
193                                         </form>
194                                         <form method="GET">
195                                                 <xsl:attribute name="action"><xsl:value-of select="concat($base_dir, 'opensearch/1.1/', $lib, '/html/subject')" /></xsl:attribute>
196                                                 <input class="searchbox" type="text" name="searchTerms" value="subjects" onfocus="this.value='';"/>
197                                         </form>
198                                         <form method="GET">
199                                                 <xsl:attribute name="action"><xsl:value-of select="concat($base_dir, 'opensearch/1.1/', $lib, '/html/series')" /></xsl:attribute>
200                                                 <input class="searchbox" type="text" name="searchTerms" value="series" onfocus="this.value='';"/>
201                                         </form>
202                                         <br/>
203                                 </div>
204                                 
205                                 <!-- text input: if present in an opensearch feed, this is probably a search box -->
206                                 <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>
207
208                                 <!-- output search results or 'no results' msg -->
209                                 <xsl:choose>
210                                         <xsl:when test="$items">
211                                                 <!-- display the search numbers -->
212                                                 <p class="nav">
213                                                         <xsl:value-of select="concat($t-results,' ')" />
214                                                         <xsl:choose>
215                                                                 <xsl:when test="$statedStartIndex&gt;0"><xsl:value-of select="$statedStartIndex" /></xsl:when>
216                                                                 <xsl:otherwise>1</xsl:otherwise>
217                                                         </xsl:choose>
218                                                         <xsl:value-of select="concat(' ', $t-resultsto, ' ')" />
219                                                         <xsl:value-of select="$endIndex" />
220                                                         <xsl:if test="$totalresults&gt;0"><xsl:value-of select="concat(' ', $t-resultsof, ' ')" /><xsl:number value="$totalresults" grouping-size="3" grouping-separator="," /></xsl:if>
221                                                         <xsl:if test="string-length($navnext)&gt;0 or string-length($navprev)&gt;0">   |   </xsl:if>
222                                                         <xsl:if test="string-length($navprev)&gt;0">
223                                                                 <a class="x-escape" href="{$navprev}" rel="previous"><xsl:value-of select="$t-prevlink" disable-output-escaping="yes" /></a>
224                                                                 <xsl:if test="string-length($navnext)&gt;0"> | </xsl:if>
225                                                         </xsl:if>
226                                                         <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>
227                                                 </p>
228                                                 <dl><xsl:apply-templates select="$items" /></dl>
229                                                 <!-- result navigation -->
230                                                 <p class="nav">
231                                                         <xsl:value-of select="concat($t-results,' ')" />
232                                                         <xsl:choose>
233                                                                 <xsl:when test="$statedStartIndex&gt;0"><xsl:value-of select="$statedStartIndex" /></xsl:when>
234                                                                 <xsl:otherwise>1</xsl:otherwise>
235                                                         </xsl:choose>
236                                                         <xsl:value-of select="concat(' ', $t-resultsto, ' ')" />
237                                                         <xsl:value-of select="$endIndex" />
238                                                         <xsl:if test="$totalresults&gt;0"><xsl:value-of select="concat(' ', $t-resultsof, ' ')" /><xsl:number value="$totalresults" grouping-size="3" grouping-separator="," /></xsl:if>
239                                                         <xsl:if test="string-length($navnext)&gt;0 or string-length($navprev)&gt;0">   |   </xsl:if>
240                                                         <xsl:if test="string-length($navprev)&gt;0">
241                                                                 <a class="x-escape" href="{$navprev}" rel="previous"><xsl:value-of select="$t-prevlink" disable-output-escaping="yes" /></a>
242                                                                 <xsl:if test="string-length($navnext)&gt;0"> | </xsl:if>
243                                                         </xsl:if>
244                                                         <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>
245                                                 </p>
246                                         </xsl:when>
247                                         <xsl:when test="(opensearch:startIndex&gt;1 or opensearchOld&gt;1) and not($totalresults=0)"><xsl:value-of select="$t-nomoreresults" /></xsl:when>
248                                         <xsl:otherwise><p><xsl:value-of select="$t-noresults" /></p></xsl:otherwise>
249                                 </xsl:choose>
250
251                                 <!-- display the copyright -->
252                                 <xsl:variable name="rights" select="(atom:rights[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml'] | copyright | dc:rights)[1]" />
253                                 <div id="footer">
254                                         <xsl:if test="$rights"><p><xsl:call-template name="showtext"><xsl:with-param name="node" select="$rights" /></xsl:call-template></p></xsl:if>
255                                         <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>
256                                 </div>
257
258                         </body>
259                 </html>
260         </xsl:template>
261         
262         <xsl:template match="textInput | rss1:textinput">
263                 <xsl:param name="query" />
264                 <xsl:if test="(name | rss1:name) and (link | rss1:link)">
265                         <xsl:variable name="formaction"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(link | rss1:link)[1]" /></xsl:call-template></xsl:variable>
266                         <form method="get" action="{$formaction}">
267                                 <input type="text" name="{name | rss1:name}" value="{$query}" />
268                                 <xsl:choose>
269                                         <xsl:when test="title | rss1:title"><input type="submit" value="{title | rss1:title}" /></xsl:when>
270                                         <xsl:otherwise><input type="submit" /></xsl:otherwise>
271                                 </xsl:choose>
272                                 <xsl:if test="description | rss1:description"><p><xsl:value-of select="(description | rss1:description)[1]" /></p></xsl:if>
273                         </form>
274                 </xsl:if>
275         </xsl:template>
276
277         <xsl:template match="atom:entry | item | //rss1:item | //rss9:item"> <!-- match="" must match the select="" earlier on -->
278                 <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>
279                 <!-- item title -->
280                 <dt>
281                         <xsl:choose>
282                                 <xsl:when test="string-length($url)&gt;0">
283                                         <a href="{$url}">
284                                                 <xsl:choose>
285                                                         <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>
286                                                         <xsl:otherwise><xsl:value-of select="$t-untitleditem" /></xsl:otherwise>
287                                                 </xsl:choose>
288                                         </a>
289                                 </xsl:when>
290                                 <xsl:otherwise>
291                                         <strong>
292                                                 <xsl:choose>
293                                                         <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>
294                                                         <xsl:otherwise><xsl:value-of select="$t-untitleditem" /></xsl:otherwise>
295                                                 </xsl:choose>
296                                         </strong>
297                                 </xsl:otherwise>
298                         </xsl:choose>
299                         <!-- item authors -->
300                         <xsl:if test="$t-authors and (author | atom:author | atom:contributor | dc:creator | dc:publisher | dc:contributor)">
301                                 <xsl:value-of select="concat(' ', $t-authors, ' ')" />
302                                 <xsl:apply-templates select="author | atom:author | atom:contributor | dc:creator | dc:publisher | dc:contributor" />
303                         </xsl:if>
304                 </dt>
305                 <!-- item description -->
306                 <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']">
307                         <dd class="desc">
308                                 <xsl:choose>
309                                         <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>
310                                         <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>
311                                 </xsl:choose>
312                                 <xsl:if test="atom:content/@src">
313                                         <xsl:if test="atom:summary"><br /></xsl:if>
314                                         <a>
315                                                 <xsl:attribute name="href"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="atom:content/@src" /></xsl:call-template></xsl:attribute>
316                                                 <xsl:value-of select="$t-entrylink" />
317                                         </a>
318                                 </xsl:if>
319                         </dd>
320                 </xsl:if>
321                 <!-- item categories -->
322                 <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>
323                 <!-- item source -->
324                 <xsl:if test="string-length($t-source)&gt;0">
325                         <xsl:variable name="maybesourceurl" select="(atom:source/link[@rel='alternate']/@href | source/@url)[1]" />
326                         <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>
327                         <xsl:variable name="maybesourcename">
328                                 <xsl:choose>
329                                         <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>
330                                         <xsl:when test="string-length(source)&gt;0"><xsl:value-of select="source[1]" /></xsl:when>
331                                         </xsl:choose>
332                         </xsl:variable>
333                         <xsl:if test="string-length($sourceurl)&gt;0 or string-length($maybesourcename)&gt;0">
334                                 <dd>
335                                         <xsl:value-of select="concat($t-source,' ')" />
336                                         <xsl:variable name="sourcename">
337                                                 <xsl:choose>
338                                                         <xsl:when test="$maybesourcename"><xsl:value-of select="$maybesourcename" /></xsl:when>
339                                                         <xsl:otherwise><xsl:value-of select="$sourceurl" /></xsl:otherwise>
340                                                 </xsl:choose>
341                                         </xsl:variable>
342                                         <xsl:choose>
343                                                 <xsl:when test="$sourceurl"><a href="{$sourceurl}"><xsl:value-of select="$sourcename" /></a></xsl:when>
344                                                 <xsl:otherwise><xsl:value-of select="$sourcename" /></xsl:otherwise>
345                                         </xsl:choose>
346                                 </dd>
347                         </xsl:if>
348                 </xsl:if>
349                 <!-- item comments -->
350                 <xsl:if test="comments and string-length($t-comments)&gt;0">
351                         <xsl:variable name="commentsurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="comments[1]" /></xsl:call-template></xsl:variable>
352                         <dd><a href="{$commentsurl}"><xsl:value-of select="$t-comments" /></a></dd>
353                 </xsl:if>
354                 <!-- item enclosure -->
355                 <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>
356                 <!-- item rights -->
357                 <xsl:variable name="itemrights" select="atom:rights[not(@type) or @type='' or @type='text' or @type='html' or @type='xhtml'][1]" />
358                 <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>
359                 <!-- item url -->
360                 <xsl:if test="string-length($url)&gt;0">
361                         <dd class="url">
362                                 <span class="unapi-uri">
363                                         <xsl:for-each select="atom:link[@rel='unapi-uri']">
364                                                 <xsl:attribute name="title">
365                                                         <xsl:value-of select="@href" />
366                                                 </xsl:attribute>
367                                         </xsl:for-each>
368                                         <xsl:choose>
369                                                 <xsl:when test="string-length(substring-after($url, 'http://'))&gt;100">
370                                                         <xsl:value-of select="concat(substring(substring-after($url, 'http://'),1,100),'&#8230;')" />
371                                                 </xsl:when>
372                                                 <xsl:otherwise>
373                                                         <xsl:value-of select="substring-after($url, 'http://')" />
374                                                 </xsl:otherwise>
375                                         </xsl:choose>
376                                 </span>
377                         </dd>
378                 </xsl:if>
379         </xsl:template>
380
381         <xsl:template match="atom:link[@rel='enclosure'] | enclosure">
382                 <xsl:variable name="encurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="(@href | @url)[1]" /></xsl:call-template></xsl:variable>
383                 <xsl:value-of select="concat($t-download, ' ')" />
384                 <a href="{$encurl}">
385                         <xsl:choose>
386                                 <xsl:when test="@title"><xsl:value-of select="@title" /></xsl:when>
387                                 <xsl:otherwise><xsl:value-of select="$t-enclosure" /></xsl:otherwise>
388                         </xsl:choose>
389                 </a>
390                 <xsl:if test="@type"> (<xsl:value-of select="@type" />)</xsl:if>
391         </xsl:template>
392
393         <xsl:template match="atom:category | category">
394                 <xsl:variable name="name">
395                         <xsl:choose>
396                                 <xsl:when test="not(namespace-uri())"><xsl:value-of select="." /></xsl:when>
397                                 <xsl:when test="@label"><xsl:value-of select="@label" /></xsl:when>
398                                 <xsl:when test="@term"><xsl:value-of select="@term" /></xsl:when>
399                         </xsl:choose>
400                 </xsl:variable>
401                 <xsl:if test="string-length($name)&gt;0">
402                         <xsl:variable name="category">
403                                 <xsl:choose>
404                                         <xsl:when test="not(namespace-uri())"><xsl:value-of select="." /></xsl:when>
405                                         <xsl:otherwise><xsl:value-of select="@term" /></xsl:otherwise>
406                                 </xsl:choose>
407                         </xsl:variable>
408                         <xsl:variable name="maybeurl" select="(@domain | @scheme)[1]" />
409                         <xsl:variable name="url">
410                                 <xsl:choose>
411                                         <xsl:when test="starts-with($maybeurl, 'http')">
412                                                 <xsl:value-of select="concat($maybeurl, '#', $category)" />
413                                         </xsl:when>
414                                         <xsl:otherwise>
415                                                 <xsl:value-of select="concat($base_dir, 'opensearch/1.1/', $lib, '/html/subject?searchTerms=', $name)" />
416                                         </xsl:otherwise>
417                                 </xsl:choose>
418                         </xsl:variable>
419                         <xsl:choose>
420                                 <xsl:when test="string-length($url)&gt;0"><a href="{$url}"><xsl:value-of select="$name" /></a></xsl:when>
421                                 <xsl:otherwise><xsl:value-of select="$name" /></xsl:otherwise>
422                         </xsl:choose>
423                         <xsl:text>; </xsl:text>
424                 </xsl:if>
425         </xsl:template>
426         
427         <!-- outputs a 'person' (next 4 templates) -->
428         <xsl:template match="dc:creator | dc:publisher | dc:contributor">
429                 <xsl:call-template name="person"><xsl:with-param name="name" select="." /></xsl:call-template>
430         </xsl:template>
431         <xsl:template match="managingEditor | webMaster | author">
432                 <xsl:call-template name="person">
433                         <xsl:with-param name="email" select="substring-before(concat(normalize-space(.),' '), ' ')" />
434                         <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>
435                 </xsl:call-template>
436         </xsl:template>
437         <xsl:template match="atom:author | atom:contributor">
438                 <xsl:call-template name="person">
439                         <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>
440                         <xsl:with-param name="email" select="atom:email" />
441                         <xsl:with-param name="name" select="atom:name" />
442                 </xsl:call-template>
443         </xsl:template>
444         <xsl:template name="person">
445                 <xsl:param name="email" />
446                 <xsl:param name="link" />
447                 <xsl:param name="name" />
448                 <xsl:variable name="showname">
449                         <xsl:choose>
450                                 <xsl:when test="string-length($name)&gt;0"><xsl:value-of select="$name" /></xsl:when>
451                                 <xsl:when test="string-length($email)&gt;0"><xsl:value-of select="$email" /></xsl:when>
452                                 <xsl:otherwise><xsl:value-of select="$link" /></xsl:otherwise>
453                         </xsl:choose>
454                 </xsl:variable>
455                 <xsl:variable name="showlink">
456                         <xsl:choose>
457                                 <xsl:when test="string-length($link)"><xsl:value-of select="$link" /></xsl:when>
458                                 <xsl:when test="string-length($email)">mailto:<xsl:value-of select="$email" /></xsl:when>
459                         </xsl:choose>
460                 </xsl:variable>
461                 <xsl:if test="string-length($showname)&gt;0">
462                         <xsl:choose>
463                                 <xsl:when test="string-length($showlink)&gt;0"><a href="{$showlink}"><xsl:value-of select="$showname" /></a></xsl:when>
464                                 <xsl:otherwise><xsl:value-of select="$showname" /></xsl:otherwise>
465                         </xsl:choose>
466                         <xsl:text>; </xsl:text>
467                 </xsl:if>
468         </xsl:template>
469         
470         <!-- outputs text/(x)html; based on code from jtesler -->
471         <xsl:template name="showtext">
472                 <xsl:param name="node" />
473                 <xsl:choose>
474                         <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>
475                         <xsl:when test="$node/@type='xhtml'"><xsl:apply-templates select="$node/xhtml:div" mode="stripXhtml" /></xsl:when>
476                         <xsl:otherwise><xsl:value-of select="$node" /></xsl:otherwise>
477                 </xsl:choose>
478         </xsl:template>
479         <!-- These templates are used for outputting the xhtml output.  We need to
480         Strip xhtml: from all the nodes.  We must also convert any href and src
481         attributes from relative to absolute if there is an xml:base -->
482         <xsl:template match="xhtml:*" mode="stripXhtml">
483                 <xsl:element name="{local-name()}">
484                         <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>
485                         <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>
486                         <xsl:apply-templates select="@* | node()" mode="stripXhtml" />
487                 </xsl:element>
488         </xsl:template>
489         <xsl:template match="node() | @*" mode="stripXhtml"><xsl:copy><xsl:apply-templates select="@* | node()" mode="stripXhtml" /></xsl:copy></xsl:template>
490         <!-- Since we already processed href and src nodes up above, don't process them again here -->
491         <xsl:template match="@href | @src" mode="stripXhtml" priority="1" />
492         
493         <!-- returns absolute links, given absolute ones or relative ones with base ones -->
494         <xsl:template name="resolvelink">
495                 <xsl:param name="url" />
496                 <xsl:param name="node" select="$url" />
497                 <xsl:choose>
498                         <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 -->
499                         <xsl:otherwise>
500                                 <xsl:variable name="basenode" select="($node/ancestor-or-self::*[@xml:base])[last()]" />
501                                 <xsl:variable name="base">
502                                                 <xsl:call-template name="resolvelink">
503                                                 <xsl:with-param name="url" select="$basenode/@xml:base" />
504                                                 <xsl:with-param name="node" select="($basenode/ancestor::*[@xml:base])[last()]" />
505                                         </xsl:call-template>
506                                 </xsl:variable>
507                                 <xsl:variable name="protocol"><xsl:if test="contains($base, '://')"><xsl:value-of select="concat(substring-before($base, '://'), '://')" /></xsl:if></xsl:variable>
508                                 <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>
509                                 <xsl:variable name="trailingslash"><xsl:if test="substring($basenoprot,string-length($basenoprot),1)='/'">true</xsl:if></xsl:variable>
510                                 <xsl:variable name="usebase">
511                                         <xsl:value-of select="$protocol" />
512                                         <xsl:choose>
513                                                 <xsl:when test="not(string-length($trailingslash)) and not(contains($basenoprot, '/'))"><xsl:value-of select="$basenoprot" />/</xsl:when>
514                                                 <xsl:when test="not(string-length($trailingslash)) and contains($basenoprot, '/') and $url != '' and not(starts-with($url, '#')) and not(starts-with($url, '?'))">
515                                                         <xsl:call-template name="uponelevel">
516                                                                 <xsl:with-param name="url" select="$basenoprot" />
517                                                         </xsl:call-template>
518                                                 </xsl:when>
519                                                 <xsl:otherwise><xsl:value-of select="$basenoprot" /></xsl:otherwise>
520                                         </xsl:choose>
521                                 </xsl:variable>
522                                 <xsl:choose>
523                                         <xsl:when test="starts-with($url,'/')"><xsl:value-of select="concat(substring-before($base, '://'), '://', substring-before(substring-after($usebase, '://'), '/'), $url)" /></xsl:when>
524                                         <xsl:when test="starts-with($url,'../')">
525                                                 <xsl:call-template name="resolvelink">
526                                                         <xsl:with-param name="url" select="substring-after($url, '../')" />
527                                                         <xsl:with-param name="base">
528                                                                 <xsl:value-of select="concat(substring-before($base,'://'), '://')" />
529                                                                 <xsl:call-template name="uponelevel"><xsl:with-param name="url" select="substring-after(substring($usebase, 0, string-length($usebase)-1), '://')" /></xsl:call-template>
530                                                         </xsl:with-param>
531                                                 </xsl:call-template>
532                                         </xsl:when>
533                                         <xsl:otherwise>
534                                                 <xsl:variable name="useurl">
535                                                         <xsl:choose>
536                                                                 <xsl:when test="starts-with($url, './')"><xsl:value-of select="substring-after($url, './')" /></xsl:when>
537                                                                 <xsl:otherwise><xsl:value-of select="$url" /></xsl:otherwise>
538                                                         </xsl:choose>
539                                                 </xsl:variable>
540                                                 <xsl:value-of select="concat($usebase, $useurl)" />
541                                         </xsl:otherwise>
542                                 </xsl:choose>
543                         </xsl:otherwise>
544                 </xsl:choose>
545         </xsl:template>
546         <xsl:template name="uponelevel">
547                 <xsl:param name="url" /> <!-- url looks like sub.domain.com/folder/two/three -->
548                 <xsl:variable name="firstpart" select="substring-before($url, '/')" />
549                 <xsl:variable name="afterslash" select="substring-after($url, '/')" />
550                 <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>
551                 <xsl:value-of select="concat($firstpart, '/', $secondpart)" />
552         </xsl:template>
553
554 </xsl:stylesheet>