Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
xmlns:p="" version="1.0"
<!-- The "source" input is the HTTP request -->
<p:input port='source' primary='true'/>
<!-- The "parameters" input port lists the environment parameters -->
<p:input port='parameters' kind='parameter' primary='true'/>
<!-- The "result" output port is for our HTTP response -->
<p:output port="result" primary="true" sequence="true"/>
<!-- What URI did the browser request? -->
<p:variable name="relative-request-uri" select="substring-after(/c:request/@href, '/xproc-z/')"/>
<!-- "related" URI is a request for a list of documents related to the referrering document -->
<p:when test="$relative-request-uri = 'related' ">
<!-- The URI of the referring page is given by the "referer" (sic) HTTP header -->
<p:variable name="referer" select="/c:request/c:header[@name='referer']/@value"/>
<!-- Construct an HTTP request containing a SPARQL query that will return a list of related documents -->
<p:xslt name="construct-sparql-query">
<p:input port="stylesheet">
<xsl:stylesheet version="2.0" xmlns:xsl="">
<xsl:template match="/c:request">
<xsl:variable name="sparql-query">
PREFIX foaf: <>
PREFIX dcterms: <>
(count(?namedEntity) as ?namedEntitiesInCommon)
?digitalObject foaf:isPrimaryTopicOf ?page.
?relatedDigitalObject foaf:isPrimaryTopicOf ?relatedPage.
?digitalObject foaf:topic ?namedEntity.
?relatedDigitalObject foaf:topic ?namedEntity.
?relatedDigitalObject dcterms:title ?relatedDigitalObjectTitle
FILTER(?relatedDigitalObject != ?digitalObject)
FILTER(?page = <«current-page»>)
GROUP BY ?relatedPage ?relatedDigitalObjectTitle
ORDER BY DESC(?namedEntitiesInCommon)
<!-- Specify an HTTP request to the SPARQL query server on localhost -->
<c:request href="http://localhost:8080/fuseki/dataset/query" method="POST">
<!-- HTTP content negotiation: demand results in XML format -->
<c:header name="Accept" value="application/sparql-results+xml"/>
<c:body content-type="application/sparql-query">
<!-- Substitute the "referer" URI into our SPARQL query -->
<!-- NB because this is running on a dev Drupal server, and the RDF metadata refers to the
production Drupal server, the referring page URI has a different hostname (i.e. not -->
<!-- so we strip off the start of the 'referer' URI and replace it with "" first. -->
<xsl:value-of select="
<!-- Send the SPARQL query to the server and get results -->
<!-- Use an XSLT to format the XML query results as an HTML list -->
<p:xslt name="format-results-as-table-of-links">
<p:with-param name="referer" select="$referer"/>
<p:input port="stylesheet">
<xsl:stylesheet version="2.0" xmlns:xsl=""
<xsl:param name="referer"/>
<xsl:template match="/sparql:sparql">
<!-- HTTP response 200 = "OK" -->
<c:response status="200">
<!-- A hint for the browser and any intermediary caches about caching this response: -->
<!-- The content we are serving up depends not just on the request URI, but ALSO -->
<!-- on the value of the "Referer" header which the browser sent. -->
<c:header name="Vary" value="Referer"/>
<c:body content-type="application/xhtml+xml">
<html xmlns="">
<style type="text/css">
* {
font-family: sans-serif;
a {
color: rgb(7, 109, 139);
text-decoration: none;
a:hover {
text-decoration: underline;
<xsl:when test="sparql:results/sparql:result/sparql:binding[@name='relatedPage']">
<xsl:for-each select="sparql:results/sparql:result">
<xsl:variable name="page" select="sparql:binding[@name='relatedPage']/sparql:uri"/>
<xsl:variable name="title" select="sparql:binding[@name='relatedDigitalObjectTitle']/sparql:literal"/>
<!-- Again, we have to substitute the base URI of the dev Drupal site back onto these URIs, -->
<!-- which would otherwise point to pages on the production Drupal site. -->
<li><a target="_parent" href="{
substring-before($referer, '/node/'),
substring-after($page, '/node/')
}"><xsl:value-of select="$title"/></a></li>
<!-- SPARQL query found no related documents -->
<p>No related documents found</p>
<!-- The browser requested some other URI (not "related") -->
<p:input port="source">
<c:response status="404">
<c:body content-type="application/xhtml+xml">
<html xmlns="">
<title>Not Found</title>
<h1>Not Found</h1>
<p>The requested resource was not found.</p>