sparql2opml noodling@en

PS. a little background added below, and an observation: I usually post about semweb stuff and I get maybe 2 or 3 comments a week. I post about semweb stuff and mention OPML and I get two comments in the time it takes to have a quick bath...and one of them contained a code fix. (I really need to make commenting much easier, but that's another story).

A couple of folks that linked to my flame on the MySQL database in the sky mentioned that I'd talked about linking semweb stuff to OPML. While doing the wood I started thinking about how you might do it - the SPARQL/XSLT route being the obvious.

The more I thought about it, the more interesting it sounded as a code exercise. I imagined that you'd have decide on what bits of the source RDF you wanted to build an outline tree from, stick those into the SPARQL, then have the XSLT pull them out into a tree. The SPARQL side is pretty trivial whether you do it per-case or just something like ?subject ?predicate ?object. But general-purpose on the XSLT side looks hard, building a tree recursively based on a few presets (say a binding from foaf:knows as the outline axis, with foaf:homepage being translated into a htmlUrl attribute, foaf:name as text attribute). To tired after doing the wood to think about that (took all day).

But I did have a go at a special case. Take a FOAF blogroll, run this SPARQL over it:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>



SELECT DISTINCT ?name ?homepage



WHERE {

?x foaf:name ?name.

?x foaf:weblog ?homepage.

}

Sling the result through this XSLT.

I tried sparql.org's processor - for some reason it didn't apply my XSLT so I had to use the W3C's servlet for that, resulting in this URI:

http://www.w3.org/2005/08/online_xslt/xslt?xslfile=http%3A%2F%2Fdannyayers.com%2Fcode%2Fmisc%2Fsparql2opml&xmlfile=http%3A%2F%2Fsparql.org%2Fsparql%3Fquery%3DPREFIX%2Bfoaf%253A%2B%253Chttp%253A%252F%252Fxmlns.com%252Ffoaf%252F0.1%252F%253E%250D%250A%250D%250ASELECT%2BDISTINCT%2B%253Fname%2B%253Fhomepage%2B%253Fmbox%2B%253Fphoto%250D%250A%250D%250AWHERE%2B%257B%250D%250A%2B%2B%2B%253Fx%2Bfoaf%253Aname%2B%253Fname.%250D%250A%2B%2B%2B%253Fx%2Bfoaf%253Aweblog%2B%253Fhomepage.%250D%250A%257D%26default-graph-uri%3Dhttp%253A%252F%252Fjournal.dajobe.org%252Fjournal%252F2003%252F07%252Fsemblogs%252Fbloggers.rdf&content-type=&submit=transform

I then tried the result on Grazr, which rejected it right away. I tweaked the XSLT, same problem. It looks like the W3C servlet is caching. Anyhow, my bath's run. Not sure if I've got the fortitude to try the general-purpose XSLT, it should be considerably easier with JSON SPARQL results. Next time I have a minute...

...

I should really explain a bit more. The idea is to create a bridge to make Semantic Web data browsable using OPML tools like Grazr. It would rely on one or two existing online services (SPARQL + XSLT), operating with a couple of static files (one SPARQL, one XSLT). If the results returned contained links in the source data (say someone's FOAF URI), those links could be templated into the "processing URI", like the one above, to make it completely transparent.

As mentioned above, doing it general-purpose would likely be quite hard work (maybe requiriring another static file to provide parameters to the XSLT). But even just having XSLT+SPARQL customised for specific kinds of source data - FOAF here, another good one might be to go from the DBLP database - would be fun, maybe even useful.

Forgetting my personal opinion of OPML, I find the setup as a whole really appealing. The data/query of the system is loosely coupled to the UI, each side being developed completely independently, the glue for it is standard online services provided by third parties and the definition of the combined product is done by yet another party. Mashup city.

@en

Danny Ayers
2006-11-12T22:04:38+01:00

Related
Comments
Edit