<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>RSLT: RDF Stylesheet Language Transformations</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Silvio Peroni</string-name>
          <email>silvio.peroni@unibo.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Fabio Vitali</string-name>
          <email>fabio@cs.unibo.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computer Science and Engineering, University of Bologna</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <fpage>7</fpage>
      <lpage>13</lpage>
      <abstract>
        <p>In this paper we introduce RSLT, a simple transformation language for RDF data. RSLT organizes the rendering of RDF statements as transformation templates associated to properties or resource types and producing HTML. A prototype based on AngularJs is presented and we also discuss some implementation details and examples. - the tool should be easy to integrate in a web-based application; - it should be as easy to represent individual RDF statements as convoluted OWL entities; - IRIs of entities should be rendered with readable and meaningful text or other representations - but they should still be available for special rendering needs (e.g., as destinations for links and HTML anchors); - complex representations of main resources should be built by combining simpler representations of lesser resources and properties.</p>
      </abstract>
      <kwd-group>
        <kwd>RDF dataset visualization</kwd>
        <kwd>RSLT</kwd>
        <kwd>templates</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        The visualization of RDF data is a hot topic for the Semantic Web community. Even if
works have been presented in the past (e.g., [
        <xref ref-type="bibr" rid="ref2 ref3 ref5 ref6 ref7">2, 3, 5–7</xref>
        ]), and some visualisation interfaces
(usually in tabular form) are supported by existing triplestores such as Virtuoso1,
visualisation tools for RDF triplestores in general are still far from the sophistication of
reporting tools for traditional databases. In particular, most of such tools display triplestore
content as tabular data where identificative, descriptive and secondary properties are
shown in exactly the same way, where the order in which properties are displayed is
totally arbitrary, where related entities are described by their plain IRI rather than textual
descriptions, and where readability is completely absent.
      </p>
      <p>This drove us to investigate the best tools to provide readable representations of RDF
datasets for the general public, and to propose basic guidelines:</p>
      <p>
        Reporting software tools have limitations, such as the complexity to integrate them
in web-based architectures or the variety and complexity of approaches in generating
and delivering the reports. Yet, we found XSLT [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] a fairly natural and sophisticated
approach to provide presentation support to XML documents, and sought to provide
something similar for OWL and RDF data.
      </p>
      <p>In this paper we introduce RSLT (RDF Stylesheet Language Transformations,
pronounced result), a simple transformation language for RDF data. RSLT organizes
rendering as transformation templates associated to resources, properties or resource
types, produces HTML and can recursively call other templates. A browser-based
prototype based on the AngularJs library has been created that allows client-based
presentations of SPARQL constructs, and soon of Turtle datasets as well. The rest of the
paper is organized as follows: in Section 2 we introduce the main constructs of RSLT. In
Section 3 we introduce some implementation details of RSLT and few examples, and in
Section 4 we conclude the paper by sketching out some future works.
2</p>
    </sec>
    <sec id="sec-2">
      <title>RSLT</title>
      <p>RDF Stylesheet Language Transformations (RSLT)2, pronounced result, is a direct and
trivial translation of (some parts of) the XSLT language into the RDF domain. Similarly
to its noble ancestor, an RSLT document contains a number of templates that create
fragments of output in some displayable format (e.g., HTML) when navigating through a
graph of RDF statements. The fact that RDF graphs, differently than XML documents,
lack a natural hierarchy in its internal organization. and that no obvious selector language
for RDF exists3 provide for some interesting complications of the original design, though.</p>
      <p>Thus, while XSLT always starts transforming the root of an XML document, no such
concept exists for RDF graphs, which therefore require a starting template such as the
following one:
&lt;template match='$start'&gt;
&lt;div class="container"&gt;
&lt;applyTemplates select="??person foaf:familyName 'Horrocks'."&gt;
&lt;/applyTemplates&gt;
&lt;/div&gt;
&lt;/template&gt;</p>
      <p>The above template will be fired at the beginning of the process and will create
an HTML div element, and will first select all entities whose foaf:familyNa me is
“Horrocks”, and then look for a reasonable template for each of them.</p>
      <p>The lack of a correspondence for XPath forced us to invent a new syntax for
&lt;applyTemplates&gt; selectors, liberally derived from the SPARQL query syntax, that
allow templates to distinguish statements from entities. Thus, the selector “?person
foaf:familyName 'Horrocks'.” with a single question mark (SQM) in the variable
selects all RDF statements whose predicate is foaf:familyName and whose object
2 RSLT is available on its GitHub repository: https://github.com/fvitali/rslt. The tool
as well as all the additional scripts are distributed under an ISC License, while the other related
files such as HTML documents are distributed under a Creative Commons Attribution 4.0
International License.
3 SPARQL cannot be considered as a pure selector language for RDF as XPath, used by XSLT, is.</p>
      <p>Rather, it is a full-featured query language, similar to XQuery for XML.
equals “Horrocks”. On the other hand, the selector “??person foaf:familyName
'Horrocks'.” with double question marks (DQM) selects a list of RSLT entities, where
each RSLT entity is defined as the set of available statements that share the same subject.
The DQM selector above can be converted as follows in SPARQL 1.1:
SELECT DISTINCT ?s ?p ?o WHERE {
?person foaf:familyName "Horrocks".</p>
      <p>{ BIND(?person as ?s) ?s ?p ?o. }
}</p>
      <p>RSLT templates can be either associated to RDF statements (by matching a triple
with one or more unbound SQM variables), to a specific resource (by matching the IRI of
the resource) or to resources of a particular type (by using a special syntax), as described
in the following excerpts:
&lt;!-- RSLT templates for RDF statements --&gt;
&lt;template match='?person foaf:familyName "Horrocks"'&gt;...&lt;/template&gt;
&lt;template match='?person foaf:familyName ?string'&gt;...&lt;/template&gt;
&lt;!-- RSLT templates for a particular resource --&gt;
&lt;template
match='http://www.semanticlancet.eu/resource/person/ian-horrocks'&gt;
...
&lt;/template&gt;
&lt;!-- RSLT templates for resources of a particular type --&gt;
&lt;template match="?person -&gt; foaf:Person"&gt; ... &lt;/template&gt;</p>
      <p>Within a template all unbound variables are bounded to the relevant RLST entities
and all associated properties are available for presentation. Any markup or content can
be placed inside templates, and RSLT constructs can be specified to refer to literals or
other resources associated to the bounded entities. Values in literal statements can be
rendered immediately through &lt;valueOf&gt; elements, while values of resource statements
are additional RSLT entities, and therefore are rendered through additional templates.
For instance, the following is a complete template of a class:
&lt;template match="?person -&gt; foaf:Person"&gt;
&lt;p&gt;Found &lt;valueOf select="count(?person pro:holdsRoleInTime ?r)"&gt;
&lt;/valueOf&gt; papers authored by
&lt;valueOf select="?person foaf:givenName ?g"&gt;&lt;/valueOf&gt;
&lt;valueOf select="?person foaf:familyName ?f"&gt;&lt;/valueOf&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;applyTemplates select='?person pro:holdsRoleInTime /</p>
      <p>pro:relatesToDocument ??work'&gt;
&lt;/applyTemplates&gt;&lt;/ul&gt;
&lt;/template&gt;</p>
      <p>Whenever the rendering engine comes across an entity of type foaf:Person, this
template is triggered, creating an HTML fragment with a &lt;p&gt; element containing text
and the values of data properties foaf:givenName and foaf:family Name, then an
&lt;ul&gt; element containing the rendering recursively produced by selecting all entities
??work related to ?person through the chain of properties pro:holdsRoleInTime /
pro:relatedToDocument. This rendering is generated by looking for and executing the
templates that match the ??work entities just selected. In order to avoid circularity in the
selection of templates, a simple approach is taken to consider the template as spent when
applied in a recursion, so it cannot be chosen and applied again inside itself. Once all
relevant templates have been spent, if a template for a specific entity is needed again, a
default one is applied that does not recurse, thus halting any potential circularity.</p>
      <p>Given the strong dependance of the current implementation of RSLT to the AngularJS
framework, a shorter syntax exists that uses the classical double brackets of the framework.
Additionally, since all entities are in fact Javascript objects and the colon “:” is a forbidden
character in Javascript variables, Java-script’s dot notation is used and the underscore is
used instead:
&lt;template match="?person -&gt; foaf:Person"&gt;
&lt;p&gt;Found {{ count(person.pro_holdsRoleInTime) }} papers authored
by {{person.foaf_givenName}} {{person.foaf_familyName}}:&lt;/p&gt;
&lt;ul&gt;
&lt;applyTemplates select='?person pro_holdsRoleInTime /</p>
      <p>pro_relatesToDocument ??work'&gt;
&lt;/applyTemplates&gt;
&lt;/ul&gt;
&lt;/template&gt;</p>
      <p>In addition to &lt;template&gt;, &lt;applyTemplates&gt; and &lt;valueOf&gt;, at the moment
the RSLT language inherits from XSLT also constructs such as &lt;callTempl ate&gt;
and &lt;forEach&gt;, that have similar behaviour as their XSLT counterparts. Also, the
template element inherits the mode and priority attributes, with similar functions to
XSLT. Finally, the &lt;rslt&gt; element allows the specification of a triple store through the
triplestore attribute, and element &lt;prefix&gt; allows the specification of prefixes for
selectors and property names.</p>
      <p>When executing &lt;applyTemplates&gt; and &lt;forEach&gt; instructions, RSLT verifies
whether the requested entities are already locally available, and if not it proceeds to
execute another SPARQL query to the triplestore. However, in order to avoid to run a
large number of queries every time RSLT templates will match, RSLT implements a
mechanism to preload (through the attribute preload) as many entities as needed, so
that no further queries (or many less queries) need to be executed. In the following listing
we show how this works, loading additional entities specified by the DQM variables in
the preload attribute:
&lt;template match='$start'&gt;
&lt;applyTemplates select="??person foaf:familyName 'Horrocks'."
preload="?person pro:holdsRoleInTime ??role.</p>
      <p>?role pro:relatesToDocument ??work."&gt;
&lt;/applyTemplates&gt;
&lt;/template&gt;</p>
      <p>In conclusion, RSLT is rather similar to its ancestor, XSLT, but for a few key
differences, such as the specification of a different selector language, and the efficiency
requirement that led us to include the preload attribute. The selector language is in itself
just a subset of the SPARQL language, similarly to how the selector language XPath is
but a subset of the query language XQuery, and for similar reasons. Would it be possible
to just use an existing implementation of XSLT? Unfortunately, the requirements for
non-circularity in template matching and the effort to adapt a new selector language to
existing code probably makes this endeavour excessive and not worthy. We have rather
reimplemented a few key commands of the language relying on a few peculiarities of
AngularJs directives, as explained in the next section.
3</p>
    </sec>
    <sec id="sec-3">
      <title>An implementation of RSLT</title>
      <p>A working implementation of the RSLT engine has been developed to run as an AngularJS
module. In its simplest incarnation, a simple specification of the libraries and one line of
Javascript is enough to have a full working instance of RSLT in the browser, as shown in
the following listing:
&lt;html ng-app="simplestRSLT"&gt;
&lt;head&gt;
&lt;script src="angular.js"&gt; &lt;/script&gt;
&lt;script src="rslt.js"&gt; &lt;/script&gt;
&lt;script&gt;</p>
      <p>var app = angular.module('simplestRSLT', ['rslt']);
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;</p>
      <p>&lt;rslt&gt; ... &lt;/rslt&gt;
&lt;/body&gt;
&lt;/html&gt;</p>
      <p>The ng-app attribute of element &lt;html&gt; is required by AngularJs to create an Angular
application (named ’simplestRSLT’), which corresponds to an empty AngularJs module
that simply includes and uses the RSLT library. Anywhere in the body of the HTML
document the &lt;rslt&gt; element creates the rendering of the entities selected in its $start
template.</p>
      <p>Each element of the RSLT language is defined as an AngularJs directive, which allows
HTML to be extended with new markup and new element names. AngularJs directives
create nested contexts where only selected objects are accessible. This is a very easy
mechanism for managing context entities in templates: namely, each template can only
access the entities that correspond to variables in the match attribute, thereby ensuring
clean and controlled processing of entities and properties. Each variable name is in fact
bound bidirectionally to a Javascript object that contains all triples of the corresponding
entity, with the additional precaution of converting into underscores all colons separating
the prefix from the actual name of the property. For instance, foaf:familyName of the
DQM variable ??person is always available as person.foaf_familyName within all
directives/factories/filters in the current scope.</p>
      <p>A little note on the RSLT syntax used in the current implementation: in AngularJs a
normalization takes place for all directive names, where colons, dashes and underscores
are removed and converted into camelCase. This means that &lt;apply-templates&gt;,
&lt;apply:templates&gt; and &lt;apply_templates&gt; are equivalent to &lt;applyTemplates&gt;.
The standard Angular recommendation is to “use name-with-dashes for attribute names
and camelCase for the corresponding directive name”, so in all our examples we are uing
&lt;applyTemplates&gt; instead of &lt;apply-templates&gt; as XSLT introduced. The same
goes for &lt;forEach&gt; and &lt;valueOf&gt; instead of &lt;for-each&gt; and &lt;value-of&gt;. They are
all equivalent.</p>
      <p>
        At the address http://www.fabiovitali.it/rslt/ you can find four working
examples of RSLT, all using as data source the Semantic Lancet Triplestore [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. The first
and the second examples are identical and show the simplest RSLT document accessing
and rendering entities and properties across seven different classes – the only difference
being in the rendering speed (which in example 1 is lacks any preload instruction in the
queries).
      </p>
      <p>
        The third example is a simple and straightforward reimplementation of the Lancet
Data Browser (http://www.semanticlancet.eu/browser) already presented in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ],
whose source code becomes incredibly simpler and more straightforward through the use
of the RSLT library. Finally, example 4 (see Fig. 1) is a tool for the RSLT programmer that
supports the interactive specifications of triplestores, start-with RSLT entities, pre-loaded
RSLT entities, and templates (both in XML as described in this paper as well as in an
experimental JSON format not yet documented) as well as checks the output of the RSLT
transformation, the actual SPARQL queries sent to the triplestore and the list of entities
that have been downloaded client-side by the full sequence of SPARQL queries generated
through the execution of the RSLT templates.
In this paper we have introduced RSLT, i.e., a simple transformation language for RDF
data. RSLT organizes rendering of RDF statements in a triplestore through transformation
templates recursively producing HTML. A prototype based on the AngularJs library
has been presented and we have discussed implementation details and examples. In the
future, there are ongoing plans to integrate support for the management of complete
collections of RDF statements under the form of Turtle files, to extend the language to
supporting more features of the XSLT language and of the query language. Finally, our
plan is to study the requirements for providing support of the language on the server as
well, by verifying how an architecture such as Node.js could be used to this end.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Bagnacani</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ciancarini</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Di</surname>
            <given-names>Iorio</given-names>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            ,
            <surname>Nuzzolese</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. G.</given-names>
            ,
            <surname>Peroni</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            ,
            <surname>Vitali</surname>
          </string-name>
          ,
          <string-name>
            <surname>F.</surname>
          </string-name>
          (
          <year>2015</year>
          ).
          <article-title>The Semantic Lancet Project: a Linked Open Dataset for Scholarly Publishing</article-title>
          .
          <source>In Proc. of EKAW</source>
          <year>2014</year>
          <article-title>Satellite Events</article-title>
          . DOI:
          <volume>10</volume>
          .1007/978-3-
          <fpage>319</fpage>
          -17966-7_
          <fpage>10</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Bischof</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Decker</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Krennwallner</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lopes</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Polleres</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          (
          <year>2012</year>
          ).
          <article-title>Mapping between RDF and XML with XSPARQL</article-title>
          .
          <source>Journal on Data Semantics</source>
          ,
          <volume>1</volume>
          (
          <issue>3</issue>
          ):
          <fpage>147</fpage>
          -
          <lpage>185</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Corby</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Faron-Zucker</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gandon</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          (
          <year>2014</year>
          ).
          <article-title>SPARQL Template: A Transformation Language for RDF</article-title>
          . https://hal.inria.fr/hal-00969068v1
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Kay</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          (
          <year>2007</year>
          ).
          <source>XSL Transformations (XSLT) Version 2.0. W3C Recommendation</source>
          , 23
          <year>January 2007</year>
          . World Wide Web Consortium. http://www.w3.org/TR/xslt20/
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Luggen</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gschwend</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bernhard</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cudré-Mauroux</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          (
          <year>2015</year>
          ).
          <article-title>Uduvudu: a Graph-Aware and Adaptive UI Engine for Linked Data</article-title>
          .
          <source>In Proc. of LDOW</source>
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Pietriga</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bizer</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Karger</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lee</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          (
          <year>2006</year>
          ).
          <article-title>Fresnel: A Browser-Independent Presentation Vocabulary for RDF</article-title>
          .
          <source>In Proc. of ISWC</source>
          <year>2006</year>
          . DOI:
          <volume>10</volume>
          .1007/11926078_
          <fpage>12</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Skjaeveland</surname>
            ,
            <given-names>M. G.</given-names>
          </string-name>
          (
          <year>2012</year>
          ).
          <article-title>Sgvizler: A JavaScript Wrapper for Easy Visualization of SPARQL Result Sets</article-title>
          .
          <source>In Proc. of the Workshops and Demo tracks of ESWC</source>
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>