A couple of months ago, while working on a project that will hopefully see the light of day soon, I realised I needed terms for singular and plural labels for properties and classes. Even with the help of SchemaWeb I couldn’t find existing terms, so I decided to cook my own, resulting in the label vocabulary with two properties:
- A relation between a term and its label in literal plural form.
- A relation between a term and its label in literal singular form.
This was not the only vocabulary I was working on at that moment, and I needed to be able to get an overview, a human-readable version. Last year I did the RDFS Explorer for basically the same purpose, but since I was entering OWL territory, it wasn’t really up to the task. Back to square one.
Transforming RDF serialised as XML into HTML sounds like a great job for XSLT, but the possible syntax variations of RDF/XML makes it next to impossible to handle arbitrary RDF/XML found in the wild. For the FOAF Explorer and my photo collection I’ve resorted to “normalizing” by parsing and reserialising with Redland by Dave Beckett prior to the actual transformation, and that has turned out to work just fine. Redland’s serialiser emits RDF/XML using only a subset of the productions in the RDF/XML Syntax Specification, a subset that leaves out some otherwise handy shortcuts in exchange for predictability.
The only problem with the output from Redland is the fact that statements aren’t grouped by subject, which would make it much easier to handle with XSLT. For the FOAF Explorer this is handled in PHP along with the serialisation, which doesn’t use Redland’s internal serialiser, but for the general case I’ve developed an XSLT that does the trick: rdf2r3x.xsl v1.0, which produces a syntax profile I hereby dub R3X for Redland Restricted RDF/XML.
In addition to grouping by subject, the rdf2r3x XSLT also handles a few more tasks that makes it possible to publish the output right away (even if it’s not pretty):
- The output for an RSS channel conforms to the defined syntax profile, including the one for the content module.
rss:descriptionelements are added for RSS classes, if not already present, based on
dc:dateelements are added when
dcterms:issuedare encountered and there isn’t already a
dc:dateelement present with the same value.
- The RDF properties
rdf:_2, etc. are converted to
- Raw input (a copy of the RSS channel from this blog)
- Output from Redland, input to
- Output from
Now, with a predictable RDF/XML document, it’s time to move on to the actual presentation of the vocabulary. Obtaining an HTML representation of the document is really not that hard anymore, but presenting the OWL constructs, e.g. subclass relationships, in a sensible manner is not easy.
Thus, the current version, owl2html.xsl v0.1, only handles a very limited subset of OWL, most notably classes, properties, subclass relationships (partially), domains and restrictions (partially). Also, it depends on meta.xsl v0.3, a set of generic rules for presenting RDF/XML as HTML.
- Raw input (the source label vocabulary)
- Intermediate output (from
- Output from
These transformations have been used for a while, but are also still under development, especially the vocabulary transformation. I’ll post updates when major changes warrant it.
As can be seen in all three of these XSLTs, they make heavy use of the XSLT
key construct. This should speed up the transformation considerably, but it seems that the different XSLT processor implementations handle them differently - in my tests
xsltproc from libxslt was considerably faster than
sabcmd from Sablotron. The last is the default XSLT processor available in PHP 4.x, while the former is what’s going into PHP 5.x - even though it’ll be a pain upgrading all my PHP to 5.x it seems it’ll be worth it.