Bookmark Publish
Description
I have been using the Bookmarks Synchronizer Firefox plugin for the past year (at least), and it's a great way to keep my bookmarks in sync. I rarely used bookmarks before it came along, because they were such a pain to deal with, and I was constantly forgetting which computer had which bookmark, etc. I generally use Firefox at work, and Bookmarks Synchronizer lets me upload my bookmarks to my web server (using WebDAV) at which point they're stored in XBEL. In Firefox 3, I use SyncPlaces, which builds on Bookmarks Synchronizer and seems to be the only Firefox 3 extension that supports XBEL and the ability to publish on your own server. At home, I use Konqueror. XBEL is Konqueror's native bookmark format, so it's a great fit.
A while back, I started following along with David Heitmeyer's "Web Development Using XML" course at Harvard Extension School. One of the projects was to write an XSLT stylesheet that transformed XBEL into a web page, preserving the nesting structure. Using this experience, and referring to Alan Gerow's XBEL WordPress plugin (no longer around, but check out his new bookmark tool: http://alan.spacemonkeymafia.com/?p=bookmarks), I came up with my own XSLT stylesheet that converted my bookmarks to a web page. That way, I can get to my bookmarks from anywhere. It worked pretty well, but I decided it needed a little dynamic HTML (everyone's doing it these days...) so when I stumbled across Chris Holland's page demonstrating how to expand and collapse sections using JavaScript, I decided it was time to finish it up. Later, I discovered jQuery, which provided a nice mechanism for selecting the elements to bind events to, and refactored the application to use that. Here is the result.
It doesn't quite look right in Internet Explorer...the links all have triangle bullets, but it looks OK in Firefox and Konqueror. Maybe I'll get around to fixing it one day. As it's my first serious attempt at XSLT, the stylesheet contains lots of comments, which might be helpful if you're also new to it.
Running it
There are various ways to transform a file using XSLT. I prefer using xsltproc, a tool that comes with libxml2. It's straightforward and you avoid the pain of Java. You can use the following command to transform a bookmark file:
xsltproc xbel.xsl my_xbel_bookmark_file.xml > my_bookmarks.htmlSince I had a cool bookmark page, I wanted to publish it on my website. But every time I add new bookmarks, I need to re-transform the XBEL file into HTML. That's a pain to do by hand, but easy enough in PHP. So, I have included a PHP script that reads the XBEL file, and if it's changed, transforms it into a new HTML file, which it serves to the user. Actually, it does two transformations. The first is to delete nodes; I don't want links to internal servers at work published on the web, so I have a stylesheet that specifically omits those nodes. The second is the actual XBEL-to-HTML transformation.
Usage
The web directory contains the elements of the webpage, a PHP file to do the transformation and present the result to the client, and the xbel.xsl stylesheet that does the work. You may want to modify the PHP file or the first stylesheet (work_filter.xsl) to tailor for your environment.
The konqueror directory contains two additional stylesheets: one that copies everything but my bookmarkets folder, and one that copies only my bookmarklets folder. (Konqueror doesn't have bookmarklets; it has Minitools, which go into a different file.) I run a shell script like the following to update my Konqueror bookmarks
#!/bin/sh
# transform to get rid of Bookmarklets
xsltproc xslt/to_konqueror_bookmarks_xml.xsl my_bookmarks.xml > ~/.kde/share/apps/konqueror/bookmarks.xml
# instead, put Bookmarklets in Minitools
xsltproc xslt/to_konqueror_minitools_xml.xsl my_bookmarks.xml > ~/.kde/share/apps/konqueror/minitools.xml
Download
Feel free to suggest improvements, especially if you see a better way to do something.