Why RDF Templates Uses Macros

I'm working on a .NET version of RDF Templates using Carp. James asked why you had to use macros to get nice NodePaths like *[rdf:type = foaf:Agent] instead of QNames based off of the namespaces in the source documents or stylesheet. It's been a while since I wrote the specification and to be honest I'd forgotten why, other than just disliking QNames in content.

After a bit of thought I remembered some of the original reasoning. You couldn't base QName expansion off of the source documents because RDF Templates and their NodePaths operate over a graph, not an instance document. The graph could have been bult from hundreds of individual instance documents each with their own namespace prefix mappings (or none if the RDF source wasn't XML based).

That leaves getting QName mappings from the stylesheet. One reason why this would be a bad idea is that it would force the stylesheet author to include namespace mappings for every QName they refer to in their NodePaths even if they never use an element from that namespace in their actual markup. Roundtripping the stylesheet through an XML processor then becomes problematic since many processors will not output unused namespace declarations and of course the only usage in the stylesheet might hidden in a NodePath inside an attribute value.

The last part of the reasoning is that macros give a lot more expressive power than QNames. A QName by definition can only represent a namespace URI and local name. A macro on the other hand can represent almost any part of a NodePath. They can contain other macros too, so you can simplify very complex expressions down to a few concise macros and get a lot of reuse througout the document. A future version of RDF Templates will also allow inclusion of stylesheets which would enable the creation of macro libraries, essentially libraries of useful RDF query expressions.

I knew there was a good reason why I avoided QNames…

2 Comments

  1. Search
    Please check the pages in the field of music…

    Trackback by Mp3 Music — 26 Mar 2005 @ 11:07 am

  2. Search
    Please check the pages in the field of music…

    Trackback by Mp3 Music — 26 Mar 2005 @ 11:57 am

Leave a comment

Sorry, the comment form is closed at this time.