RDFTwig

RDFTwig is a set of XSLT extension functions for accessing an RDF graph dynamically from XSLT.

See:
          Description

Packages
com.nwalsh.xslt  
com.nwalsh.xslt.saxon  
com.nwalsh.xslt.xalan  

 

RDFTwig is a set of XSLT extension functions for accessing an RDF graph dynamically from XSLT. These functions make it easy to write stylesheets that process RDF graphs without having to choose a single, canonical tree representation for the graph.

The underlying RDF model is accessed with the Jena Semantic Web Toolkit. The Saxon XSLT processor is supported. Support for Xalan is anticipated.

How Does It Work?

Suppose you had an RDF graph that contained, among other things, a collection of names and addresses. You could load the graph and select the contacts like this:

<xsl:stylesheet ...
                xmlns:rt="http://nwalsh.com/xslt/ext/com.nwalsh.xslt.saxon.RDFTwig"
                exclude-result-prefixes="rt"
                ...>

<xsl:template match="/">
  <-- load the model -->
  <xsl:variable name="model" select="rt:load('/path/to/your/model.rdf')"/>

  <-- construct an rdf:type property -->
  <xsl:variable name="rdf:type"
                select="rt:property('http://www.w3.org/1999/02/22-rdf-syntax-ns#',
                                    'type')"/>

  <-- construct a resource for the rdf:type value of your contacts -->
  <xsl:variable name="contactType"
                select="rt:resource('uri-of-your-contact-type')"/>

  <-- find all the resources in the model that have the specified rdf:type -->
  <xsl:variable name="allContacts"
                select="rt:find($rdf:type, $contactType)"/>
  ...

Now, if you wanted to, you could filter those results:

  <-- construct an last name property -->
  <xsl:variable name="surnameProp"
                select="rt:property('uri-of-your-property-type',
                                    'surname')"/>

  <-- find all the Walshes -->
  <xsl:variable name="walshes"
                select="rt:filter($allContacts, $surnameProp, 'Walsh')"/>

Finally, you have several options for turning the results into an XML tree. Consider the following graph:

RDF Graph