Sébastien Laborie



We propose an extension to SPARQL that allows to generate any kind of XML documents from RDF data and a given XML template. Thanks to this extension, an XML template can itself contain queries that can import template instances. A Java implementation of this proposal is available here.

Generate XML documents with SPARQL

The SPARQL CONSTRUCT clause is exclusively limited to use an RDF graph pattern. We extend this clause to allow using XML templates in the following way:

CONSTRUCT <cityTable.html> FROM <an RDF dataset> WHERE { ... }

such that cityTable.html is an example of a URL referring to an XML template that we want to construct. An XML template is simply an XML document with some variables. These variables represents fields that will be instantiated from the query result.

XML Templates with such SPARQL queries

This XML template presents a modular XML template of a web page containing one query environment (i.e., <sparqlmm:div>):

  • The query tag (i.e., <sparqlmm:query>) finds information about cities and transportation means linking them from this RDF graph. Moreover, it retrieves information about images and descriptions of cities from two web pages encoded in XHTML+RDFa: FamousCitiesInEurope.html and FamousCitiesInFrance.html. Thereafter, it constructs, inter alia, the given imported template from this information.
  • The construct tag (i.e., <sparqlmm:construct>) contains some query variables, such as Price, which are replaced when a solution to the query is found.

The three following web pages are solutions for this modular template: Solution 1, Solution 2 and Solution 3.

Valid XHTML 1.0 Transitional