Skip to content

Commit

Permalink
Basic link browsing works #66
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinMaudry committed Oct 5, 2014
1 parent 95c85d5 commit 4eb880c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 105 deletions.
36 changes: 22 additions & 14 deletions dita2rdf/src/xsl/browser.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<xsl:import href="browser/queries.xsl"/>
<xsl:import href="browser/allMaps.xsl"/>
<xsl:import href="browser/allTopics.xsl"/>
<xsl:import href="browser/view/dataset.xsl"/>
<xsl:import href="browser/view/context.xsl"/>
<xsl:import href="browser/view/map.xsl"/>
<xsl:import href="browser/view/topic.xsl"/>
<xsl:import href="browser/view/table.xsl"/>
<xsl:import href="browser/view/stats.xsl"/>

<xsl:param name="sparql"/>
<xsl:param name="outputFolder"/>
Expand All @@ -22,19 +23,19 @@
<xsl:output method="xhtml" encoding="UTF-8"/>

<xsl:template match="/">
<xsl:variable name="datasets" as="element()">
<xsl:variable name="contexts" as="element()">
<xsl:call-template name="colin:getData">
<xsl:with-param name="queryName" select="'datasets'"/>
<xsl:with-param name="queryName" select="'contexts'"/>
<xsl:with-param name="uri"></xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:apply-templates>
<xsl:with-param name="data" select="$datasets" as="element()" tunnel="yes"/>
<xsl:with-param name="currentPageType" select="'datasets'" tunnel="yes"/>
<xsl:with-param name="data" select="$contexts" as="element()" tunnel="yes"/>
<xsl:with-param name="currentPageType" select="'contexts'" tunnel="yes"/>
</xsl:apply-templates>
<xsl:call-template name="dataset">
<xsl:call-template name="context">
<xsl:with-param name="template" select="/" tunnel="yes"/>
<xsl:with-param name="data" select="$datasets" as="element()"/>
<xsl:with-param name="data" select="$contexts" as="element()"/>
</xsl:call-template>
<xsl:call-template name="maps">
<xsl:with-param name="template" select="/" tunnel="yes"/>
Expand All @@ -61,7 +62,7 @@
<xsl:param name="currentPageType" tunnel="yes"/>
<xsl:param name="objectInfo" tunnel="yes"/>
<xsl:choose>
<xsl:when test="$currentPageType='datasets'">
<xsl:when test="$currentPageType='contexts'">
<xsl:call-template name="colin:homeSidebar"/>
</xsl:when>
<xsl:otherwise>
Expand All @@ -85,11 +86,11 @@
<xsl:param name="data" tunnel="yes"/>
<xsl:param name="objectInfo" tunnel="yes"/>
<xsl:variable name="query">
<xsl:value-of select="$queries/query[@name='datasets']"/>
<xsl:value-of select="$queries/query[@name='contexts']"/>
</xsl:variable>
<xsl:variable name="title">
<xsl:choose>
<xsl:when test="$currentPageType='datasets'">Datasets</xsl:when>
<xsl:when test="$currentPageType='contexts'">Contexts</xsl:when>
<xsl:otherwise>
<span class="label label-default"><xsl:value-of select="colin:prettifyVariableName($currentPageType)"/></span>
<xsl:text> </xsl:text>
Expand All @@ -99,8 +100,15 @@
</xsl:variable>
<div>
<xsl:apply-templates select="@*"/>
<h1><xsl:copy-of select="$title"/></h1>
<xsl:apply-templates select="$data" mode="table"/>
<div class="well well-sm" id="datanav" style="position: fixed; width: 100%;">
<h1><xsl:copy-of select="$title"/></h1>
<a class="btn btn-primary" role="button" href="#links">Links</a>
<a class="btn btn-primary" role="button" href="#stats">Stats</a>
</div>
<xsl:apply-templates select="$data" mode="table">
<xsl:with-param name="location" select="'center'"/>
</xsl:apply-templates>
<xsl:call-template name="stats"/>
</div>
</xsl:template>

Expand All @@ -118,7 +126,7 @@
<xsl:param name="currentPageType"/>
<xsl:param name="uri"/>
<xsl:variable name="uriPath" select="substring-after($uri,$config/config/resourcesBaseUri/@uri)"/>
<xsl:if test="$currentPageType='datasets'">
<xsl:if test="$currentPageType='contexts'">
<xsl:text>resources/</xsl:text>
</xsl:if>
<xsl:value-of select="concat(translate($uriPath,'/','_'),'.html')"/>
Expand All @@ -141,7 +149,7 @@
<xsl:template match="@href[not(starts-with(.,'http'))] | @src[not(starts-with(.,'http'))]">
<xsl:param name="currentPageType" tunnel="yes"/>
<xsl:attribute name="{local-name()}">
<xsl:if test="$currentPageType != 'datasets'">
<xsl:if test="$currentPageType != 'contexts'">
<xsl:text>../</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
Expand Down
54 changes: 0 additions & 54 deletions dita2rdf/src/xsl/browser/datasets.srx

This file was deleted.

31 changes: 14 additions & 17 deletions dita2rdf/src/xsl/browser/queries.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<xsl:param name="queries" as="node()">
<queries>
<query name="datasets" replace="no">
<query name="contexts" replace="no">
PREFIX dcat: &lt;http://www.w3.org/ns/dcat#>
PREFIX dita: &lt;http://purl.org/dita/ns#>
PREFIX dcterms: &lt;http://purl.org/dc/terms/>
Expand All @@ -39,7 +39,7 @@
}
ORDER BY ?extraction_time
</query>
<query name="dataset" replace="yes">
<query name="context" replace="yes">
PREFIX dcat: &lt;http://www.w3.org/ns/dcat#>
PREFIX dita: &lt;http://purl.org/dita/ns#>
PREFIX dcterms: &lt;http://purl.org/dc/terms/>
Expand Down Expand Up @@ -123,23 +123,20 @@
WHERE
{ GRAPH ?graph
{ { ?uri dita:xref ?refobject .
?refobject &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type> dita:Xref
?refobject a dita:Xref
}
UNION
{ ?uri dita:link ?refobject .
?refobject &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type> dita:Link
?refobject a dita:Link
}
?refobject &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?typeUri
?refobject a ?typeUri
{ ?refobject dita:format "html" .
?refobject dita:href ?thing
BIND(?thing AS ?title)
}
?refobject dita:href ?title .}
UNION
{ ?refobject dita:href ?thing }
OPTIONAL
{ ?thing &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type> dita:Doctype .
?thing dita:id ?id
}
{ ?refobject dita:href ?thing .
?thing a dita:Doctype .
?thing dita:id ?id .}

OPTIONAL
{ ?thing dita:title ?title }
}
Expand All @@ -154,7 +151,7 @@
PREFIX dita: &lt;http://purl.org/dita/ns#>
PREFIX dcterms: &lt;http://purl.org/dc/terms/>

SELECT DISTINCT ?thing (GROUP_CONCAT(DISTINCT ?typeLabel; SEPARATOR=', ') AS ?types) ?title ?relationLabel
SELECT DISTINCT ?thing ?title (GROUP_CONCAT(DISTINCT ?typeLabel; SEPARATOR=', ') AS ?types) ?relation
WHERE
{ GRAPH ?graph
{ ?refObject dita:href ?uri .
Expand All @@ -165,12 +162,12 @@
{ ?thing dita:title ?title }
GRAPH &lt;http://purl.org/dita/ns>
{ ?rel rdfs:subPropertyOf dita:referenceObject .
?rel rdfs:label ?relationLabel .
?rel rdfs:label ?relation .
?typeUri rdfs:label ?typeLabel
}
}
}
GROUP BY ?thing ?title ?relationLabel
GROUP BY ?thing ?title ?relation
</query>
</queries>
</xsl:param>
Expand All @@ -190,7 +187,7 @@
</xsl:choose>
</xsl:variable>
<xsl:variable name="queryUrl" select="concat($sparqlRoot,$queryText,'&amp;output=xml')"></xsl:variable>
<xsl:message select="concat('Query ',$queryName,' ',$queryUrl)"></xsl:message>
<xsl:message select="concat('Query ',$queryName,': ',$queryUrl)"></xsl:message>
<xsl:copy-of select="document($queryUrl)/*"/>
</xsl:template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
xmlns:colin="http://colin.maudry.com/"
xmlns:doc="http://www.oxygenxml.com/ns/doc/xsl" xmlns:s="http://www.w3.org/2005/sparql-results#"
exclude-result-prefixes="colin xs doc s">
<xsl:template name="dataset">
<xsl:template name="context">
<xsl:param name="data"/>
<!-- This template goes through each data set and make an HTML file. -->
<xsl:apply-templates select="$data/s:results/s:result" mode="dataset"/>
<xsl:apply-templates select="$data/s:results/s:result" mode="context"/>

</xsl:template>

<xsl:template mode="dataset" match="s:result">
<xsl:template mode="context" match="s:result">
<xsl:param name="template" tunnel="yes"/>
<xsl:result-document method="xhtml" href="{$outputFolder}/{colin:uri2path('dataset',s:binding[@name='thing']/s:uri)}">
<xsl:call-template name="datasetPage">
<xsl:result-document method="xhtml" href="{$outputFolder}/{colin:uri2path('context',s:binding[@name='thing']/s:uri)}">
<xsl:call-template name="contextPage">
<xsl:with-param name="objectInfo" select="." tunnel="yes"/>
</xsl:call-template>
</xsl:result-document>
</xsl:template>

<xsl:template name="datasetPage">
<xsl:template name="contextPage">
<xsl:param name="objectInfo" tunnel="yes"/>
<xsl:param name="template" tunnel="yes"/>
<xsl:apply-templates select="$template/*">
<xsl:with-param name="data" as="element()" tunnel="yes">
<xsl:call-template name="colin:getData">
<xsl:with-param name="queryName">dataset</xsl:with-param>
<xsl:with-param name="queryName">context</xsl:with-param>
<xsl:with-param name="uri" select="$objectInfo/s:binding[@name='thing']/s:uri"></xsl:with-param>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="currentPageType" select="'dataset'" tunnel="yes"/>
<xsl:with-param name="currentPageType" select="'context'" tunnel="yes"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
2 changes: 1 addition & 1 deletion dita2rdf/src/xsl/browser/view/map.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<xsl:template mode="map" match="s:result">
<xsl:param name="template" tunnel="yes"/>
<xsl:variable name="targetFileUrl" select="concat($outputFolder,'/',colin:uri2path('map',s:binding[@name='thing']/s:uri))"/>
<xsl:if test="preceding-sibling::s:result[1]/s:binding[@name='thing']/s:uri/text() != s:binding[@name='thing']/s:uri/text()">
<xsl:if test="not(preceding-sibling::s:result) or preceding-sibling::s:result[1]/s:binding[@name='thing']/s:uri/text() != s:binding[@name='thing']/s:uri/text()">
<xsl:result-document method="xhtml" href="{$outputFolder}/{colin:uri2path('map',s:binding[@name='thing']/s:uri)}">
<xsl:call-template name="mapPage">
<xsl:with-param name="objectInfo" select="." tunnel="yes"/>
Expand Down
27 changes: 27 additions & 0 deletions dita2rdf/src/xsl/browser/view/stats.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:colin="http://colin.maudry.com/"
xmlns:doc="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:s="http://www.w3.org/2005/sparql-results#"
exclude-result-prefixes="colin doc s">


<xsl:template name="stats">
<xsl:param name="currentPageType" tunnel="yes"/>

<xsl:choose>
<xsl:when test="$currentPageType='map'">
<xsl:call-template name="mapStats"/>
</xsl:when>
</xsl:choose>

</xsl:template>

<xsl:template name="mapStats">

<div id="mapGraph">
</div>

</xsl:template>

</xsl:stylesheet>
28 changes: 17 additions & 11 deletions dita2rdf/src/xsl/browser/view/table.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
exclude-result-prefixes="colin doc s">
<xsl:template mode="table" match="s:sparql">
<xsl:param name="head" select="s:head" as="node()"/>
<xsl:param name="location"/>
<table class="table browsable sortable">
<xsl:if test="$location='center'">
<xsl:attribute name="id">links</xsl:attribute>
</xsl:if>
<caption><span class="badge pull-right"><xsl:value-of select="count(s:results/s:result[count(s:binding)=count($head/s:variable)])"/></span></caption>
<thead>
<tr>
<xsl:apply-templates select="$head/s:variable/@name"/>
<xsl:for-each select="$head/s:variable/@name">
<xsl:if test=".!='thing'">
<xsl:variable name="name" as="text()">
<xsl:value-of select="."/>
</xsl:variable>
<th><xsl:value-of select="colin:prettifyVariableName($name)"/></th>
</xsl:if>
</xsl:for-each>
</tr>
</thead>
<xsl:apply-templates select="s:results" mode="table">
<xsl:with-param name="head" select="$head" tunnel="yes"/>
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="s:variable/@name">
<xsl:variable name="name" as="text()">
<xsl:value-of select="."/>
</xsl:variable>
<th><xsl:value-of select="colin:prettifyVariableName($name)"/></th>
</xsl:template>
<xsl:template match="s:variable/@name['thing']" priority="2"/>
<xsl:template match="s:results" mode="table">
<tbody>
<xsl:apply-templates select="s:result" mode="table"/>
Expand Down Expand Up @@ -61,16 +66,17 @@
<xsl:template match="s:result[s:binding[@name='title']/s:literal/text()='' and s:binding[@name='id']/s:literal/text()='']"/>
<xsl:template match="s:binding" mode="table" priority="-1">
<xsl:param name="path"/>
<td><a href="{$path}"><xsl:value-of select="."/></a></td>
<td class="{@name}"><a href="{$path}"><xsl:value-of select="."/></a></td>
</xsl:template>
<xsl:template mode="table" match="s:binding[s:literal/@datatype='http://www.w3.org/2001/XMLSchema#dateTime']">
<xsl:param name="path"/>
<td><a href="{$path}"><xsl:value-of select="format-dateTime(s:literal,'[M01]/[D01]/[Y0001] [H01]:[m01]')"/></a></td>
<td class="{@name}"><a href="{$path}"><xsl:value-of select="format-dateTime(s:literal,'[M01]/[D01]/[Y0001] [H01]:[m01]')"/></a></td>
</xsl:template>

<xsl:template name="inboundTable">
<xsl:param name="inboundData"/>
<div class="col-sm-3 panel panel-default" role="navigation">
<div class="col-sm-3 panel panel-default placeholder"></div>
<div class="col-sm-3 panel panel-default inbound" role="navigation">
<div class="panel-heading">Inbound links</div>
<xsl:apply-templates select="$inboundData" mode="table"/>
</div>
Expand Down

0 comments on commit 4eb880c

Please sign in to comment.