Go to content Go to navigation


XSLT+SPARQL is a set of extension functions for XSLT, the XML transformation language. These functions can execute SPARQL queries against RDF datasets, and the results can be accessed using XPath. In this way, it is possible to write XSLT transformations which access data that is expressed in RDF, regardless of its serialization (RDF/XML, N3...). Some functions can execute queries against remote SPARQL endpoints.

Compiling the sources

You'll need Maven and a Java compiler. Maven will take care of all the dependencies. Just unpack the sources and run the following command at the top-level directory (the one that contains pom.xml):

$ mvn compile

Running a transformation

The trickiest part of running a transformation using XSLT+SPARQL is to correctly set-up the Java classpath. A shell script (for UNIX systems) is included in the distribution to help the user to set-up the classpath. However, the user must set the value for the $M2_REPO to point to the Maven local repository (i.e.: the directory where Maven stores the dependency JARs). In UNIX systems, this is usually $HOME/.m2/repository.

To run an example, execute the following command from the top-level directory:

$ ./xslt-sparql.sh examples/dbpedia-actors.xsl examples/dbpedia-actors.xsl

The first parameter is the path to the XSLT stylesheet. The second parameter is the path to the XML input file (required). Note that some stylesheets ignore the XML input file, but anyway a XML input file must be provided. In such case, you can provide the path to any valid XML file, for instance, the stylesheet file, as in the example above.

The pure-XSLT implementation

Besides the Java implementation of XSLT+SPARQL, a partial implementation in pure XSLT is also provided. Actually, only two functions are available in the pure-XSLT implementation: sparql:sparqlEndpoint and sparql:commonPrefixes. Please read the documentation to learn more about the limitations of the pure-XSLT implementation.

This implementation comprises just one file, examples/pure-xslt-impl.xsl. A demo is also available, and can be run with a XSLT 2.0 processor, such as Saxon9. Use the following command in the examples directory:

$ java -jar /path/to/saxon9.jar test-pure-xslt-impl.xsl test-pure-xslt-impl.xsl


The book Linking Enterprise Data (David Wood, ed.) cites XSLT+SPARQL (pp. 233).