|
|||||||||||
PREV NEXT | FRAMES NO FRAMES |
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.
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:
Using rdf:leaf
will return a node containing all
the properties. If the properties are themselves resources, they are
represented in with an rdf:resource attribute on the property:
Using rdf:twig
will return a node containing a
breadth-first traversal. Properties will be expanded the first time
they are encountered. Optionally, the depth of the twig can be
limited.
Using rdf:branch
will return a node containing a
breadth-first traversal. Properties will be expanded every time
they are encountered, unless it would create a loop.
Optionally, the depth of the branch can be limited.
Finally, using rdf:dftwig
will return a node containing a
depth-first traversal. Properties will be expanded the first time
they are encountered. Optionally, the depth of the twig can be limited.
The selected graph can then be accessed just like a source tree:
<-- process the walshes --> <xsl:apply-templates select="rt:twig($walshes)/twig:result"/>
FIXME: write more documentation!
|
|||||||||||
PREV NEXT | FRAMES NO FRAMES |