help   |   preferences

So, you want to display search results on your website?

Here we provide a stylesheet (XSL file) that will convert OpenSearch Response feeds into HTML. You can use it on your website, or anywhere else, for free, as we’re licensing it under a Creative Commons license. It’s a good idea to use this stylesheet on your own OpenSearch feeds, so that users can see actual search results instead of raw XML.

See also other OpenSearch Readers.

The Files

Here are the three files used: the stylesheet, and two associated files.

How to Use the Stylesheet

  1. Get the files
    • Download the three files. The os.xsl file is necessary. The os.css file makes it look pretty, so you probably want that too. The os.js file is used to handle web browsers that don’t support all of the stylesheet functionality needed (details).
    • Save the files to some location where you can use them, it doesn’t really matter where.
  2. Find an OpenSearch feed that you want to display
    • That part is up to you; create your own or try A9.com’s list of OpenSearches.
  3. Apply the Stylesheet
    • You have two choices here: use the built-in XSLT parser available with most modern web browsers, or make use of another parser. See details
    • To use browsers’ built-in parsers, simply add this line to the OpenSearch Response, right below the XML declaration (<?xml … ?>):
      <?xml-stylesheet href="os.xsl" type="text/xsl" ?>
      and adjust the href attribute to the location of your xsl file.
    • You may need to adjust the links to the next and previous pages of search results so that they also have the stylesheet applied to them.
    • Link to the OpenSearch feed.

Features

Warning: jargon alert. The stylesheet will transform any OpenSearch feed into HTML. Assuming that the feed contains valid XHTML (or no HTML at all), the transformation should be valid XHTML 1.0. Please note that potentially malicious code (such as Javascript) is not dealt with.

It is capable of transforming both OpenSearch RSS 1.0 and OpenSearch 1.1 Response feeds, in any of the following syndication formats: RSS 0.9, 0.91, 0.92, 0.93, 1.0, and 2.0, and Atom 1.0. It does not yet make use of suggested searches using OpenSearch Query. It is liberal, which means that it will try to make errors invisible to the user (it should ‘just work’), even if there are problems with the OpenSearch elements, or even if there is no feed at all. The stylesheet makes use of a variety of information, including supporting a number of RSS/Atom elements and popular extensions, such as author and category information. This, along with all text on the page, is configurable; see advanced usage.

Advanced Usage

Translations and Text Changes

It is actually quite simple to change any of the text used for the search results. Note, the language of the actual OpenSearch feed is not affected by any of this; just the text that the stylesheet adds on top of that. There is a section at the top of the os.xsl file where all the bits of text used are stored, along with descriptions of what each is used for. You can edit the os.xsl file in any text editor.

The section to edit should be easy to find; it is near the top, just below the <xsl:output /> element. Each bit of text will look something like this: <xls:variable name="t-noresults">Sorry, no results were found.</xsl:variable>; an <xls:variable /> element with a name describing the bit of text, and containing the text. This specific example is the text that is displayed when there are no search results. Simply change the text and you’re done.

If you translate the stylesheet into another language, we’d love to hear about it: please let us know.

Settings

The text used for translations is also used for settings, such as whether or not to display author information if it is available. The options are described in the source code, so see the above section for details.

Customize Anything

Any of the files can be customized all you want. Go crazy!

Within another Page

The stylesheet is currently designed to create a whole web page. If you want to display an OpenSearch™ feed within another page, you will have to use the XSLT on your web server, and modify it to remove some of the HTML (e.g. the <head>).

Technical Details: XSLT

The stylesheet is an XSLT. Modern web browsers such as Firefox, Internet Explorer, Safari (1.3 and up), and Opera have XSLT parsers built-in. If you would prefer to do the transformation on your web server (rather than client-side), you’ll need to make use of one of the publicly available XSLT parsers.

The XSLT parser used by the Mozilla browser (and derivatives, such as Firefox) does not support a certain XSLT command that is required for the stylesheet to work properly. The Javascript file (os.js) available here corrects for that problem. If you know you won’t need to deal with that parser, then you do not need the Javascript file, and you should modify the use-doe-hack variable near the top of the stylesheet.

License

All three files listed above are licensed under the Creative Commons Attribution-ShareAlike 2.5 License.