-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparql-html.xsl
299 lines (283 loc) · 9.45 KB
/
sparql-html.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?xml version="1.0"?>
<!--
sparql-html.xsl, version 0.2 (2006-07-11):
XSLT for transformation of SPARQL Query Results XML Format into XHTML.
Copyright (c) 2005 Morten Frederiksen
License: http://www.gnu.org/licenses/gpl
or: http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
-->
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dawg1="http://www.w3.org/2001/sw/DataAccess/rf1/result"
xmlns:dawg="http://www.w3.org/2001/sw/DataAccess/rf1/result2"
xmlns:res="http://www.w3.org/2005/sparql-results#"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="dawg1 dawg res"
version="1.0">
<xsl:output
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes"
method="xml"/>
<xsl:param name="_now" select="false()"/>
<xsl:param name="_id"/>
<xsl:param name="_uri"/>
<xsl:param name="sparql-query"/>
<xsl:param name="sparql-query-lang"/>
<xsl:param name="sparql-data"/>
<xsl:param name="sparql-format"/>
<xsl:param name="sparql-output-xslt"/>
<xsl:param name="sparql-output-type"/>
<!-- Create document from SPARQL Query Results XML Format -->
<xsl:template match="/">
<html xml:lang="en" lang="en">
<head>
<title>Results</title>
<link rel="stylesheet" type="text/css" href="common.css" />
<link rel="stylesheet" type="text/css" href="meniu.css" />
<style>
table { border: 1px solid #999 }
th { border: 1px solid #666 }
td { border: 1px solid #ccc }
</style>
</head>
<body>
<div id="meniu">
<a href="index.php">Home</a>
<a href="sparql-editor.html">Query editor</a>
</div>
<div id="hr"></div>
<h3 style="padding-left:50px;margin-top:220px;">Results Table</h3>
<div style="padding-left:50px;">
<xsl:if test="string-length($sparql-query)!=0">
<p>
<xsl:text>Results for </xsl:text>
<xsl:choose>
<xsl:when test="$sparql-query-lang='rdql'">RDQL</xsl:when>
<xsl:otherwise>SPARQL</xsl:otherwise>
</xsl:choose>
<xsl:text> query</xsl:text>
<xsl:if test="string-length($sparql-query)!=0">
<xsl:text>: </xsl:text>
<pre>
<xsl:value-of select="$sparql-query"/>
</pre>
</xsl:if>
</p>
</xsl:if>
<table>
<xsl:apply-templates mode="root" select="/dawg1:sparql/*|/dawg:sparql/*|/res:sparql/*"/>
</table>
<!-- <h3><a href="javascript:show_xml();">Raw SPARQL XML</a></h3>
<pre id="rawxml">
<xsl:apply-templates mode="dump" select="/*"/>
</pre>
-->
</div>
<div id="bottom">
<img src="opendata.png" alt="opendata" />
<img src="http://i.creativecommons.org/p/zero/1.0/80x15.png" style="border-style: none;" alt="CC0" />
<p xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#">
<a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"></a>
<br /> To the extent possible under law,<a rel="dct:publisher" href="http://www.science3point0.com/opendata/">
<span property="dct:title">Science3.0</span></a>
has waived all copyright and related or neighboring rights to
<span property="dct:title">CC0 RDF Hosting For Scientists</span>.
This work is published from:
<span property="vcard:Country" datatype="dct:ISO3166" content="GB" about="http://www.science3point0.com/opendata/">
United Kingdom</span>.</p></div>
</body>
</html>
</xsl:template>
<!-- Process head element -->
<xsl:template mode="root" priority="0.2" match="dawg1:head[dawg1:variable and ../dawg1:results[dawg1:result]]|dawg:head[dawg:variable and ../dawg:results[dawg:result]]|res:head[res:variable and ../res:results[res:result]]">
<tr>
<xsl:apply-templates mode="variable" select="*"/>
</tr>
</xsl:template>
<!-- Process variable elements -->
<xsl:template mode="variable" match="dawg1:variable|dawg:variable|res:variable">
<th>
<xsl:value-of select="@name"/>
</th>
</xsl:template>
<!-- Process results element -->
<xsl:template mode="root" priority="0.2" match="dawg1:results[dawg1:result]|dawg:results[dawg:result]|res:results[res:result]">
<xsl:apply-templates mode="result" select="dawg1:result|dawg:result|res:result"/>
</xsl:template>
<!-- First order elements other than head or results must be an error -->
<xsl:template mode="root" priority="0.1" match="*[1]">
<tr>
<td>
<xsl:text>No results.</xsl:text>
</td>
</tr>
</xsl:template>
<!-- Process result elements -->
<xsl:template mode="result" match="dawg1:result|dawg:result|res:result">
<tr>
<xsl:apply-templates mode="binding" select="dawg1:*|dawg:binding|res:binding"/>
</tr>
</xsl:template>
<!-- Process binding element -->
<xsl:template mode="binding" match="dawg1:*|dawg:binding|res:binding">
<td>
<xsl:apply-templates mode="value" select="."/>
</td>
</xsl:template>
<!-- String value of binding for first draft -->
<xsl:template mode="value" match="dawg1:*">
<xsl:choose>
<xsl:when test="@uri">
<a href="{@uri}">
<xsl:value-of select="@uri"/>
</a>
</xsl:when>
<xsl:when test="@bnodeid">
<xsl:text>(</xsl:text>
<xsl:value-of select="@bnodeid"/>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:when test="@datatype">
<xsl:value-of select="text()"/>
<xsl:text> ^^ </xsl:text>
<xsl:value-of select="@datatype"/>
</xsl:when>
<xsl:when test="@xml:lang">
<xsl:value-of select="text()"/>
<xsl:text> @ </xsl:text>
<xsl:value-of select="@xml:lang"/>
</xsl:when>
<xsl:when test="string-length(text())!=0 or not(@bound='false')">
<xsl:value-of select="text()"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>-</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- String value of binding for second draft -->
<xsl:template mode="value" match="dawg:binding">
<xsl:choose>
<xsl:when test="dawg:uri">
<a href="{dawg:uri}">
<xsl:value-of select="dawg:uri"/>
</a>
</xsl:when>
<xsl:when test="dawg:bnode">
<xsl:text>(</xsl:text>
<xsl:value-of select="dawg:bnode"/>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:when test="dawg:literal[@datatype]">
<xsl:value-of select="dawg:literal/text()"/>
<xsl:text> ^^ </xsl:text>
<xsl:value-of select="dawg:literal/@datatype"/>
</xsl:when>
<xsl:when test="dawg:literal[@xml:lang]">
<xsl:value-of select="dawg:literal/text()"/>
<xsl:text> @ </xsl:text>
<xsl:value-of select="dawg:literal/@xml:lang"/>
</xsl:when>
<xsl:when test="dawg:literal">
<xsl:value-of select="dawg:literal/text()"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>-</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- String value of binding for final (?) draft -->
<xsl:template mode="value" match="res:binding">
<xsl:choose>
<xsl:when test="res:uri">
<a href="{res:uri}">
<xsl:value-of select="res:uri"/>
</a>
</xsl:when>
<xsl:when test="res:bnode">
<xsl:text>(</xsl:text>
<xsl:value-of select="res:bnode"/>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:when test="res:literal[@datatype]">
<xsl:value-of select="res:literal/text()"/>
<xsl:text> ^^ </xsl:text>
<xsl:value-of select="res:literal/@datatype"/>
</xsl:when>
<xsl:when test="res:literal[@xml:lang]">
<xsl:value-of select="res:literal/text()"/>
<xsl:text> @ </xsl:text>
<xsl:value-of select="res:literal/@xml:lang"/>
</xsl:when>
<xsl:when test="res:literal">
<xsl:value-of select="res:literal/text()" disable-output-escaping="yes" />
</xsl:when>
<xsl:otherwise>
<xsl:text>-</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Dump XML... -->
<xsl:template mode="dump" match="*">
<xsl:param name="indent" select="0"/>
<xsl:apply-templates mode="indent" select=".">
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>
<xsl:text><</xsl:text>
<xsl:value-of select="local-name()"/>
<xsl:if test="namespace-uri()!=namespace-uri(..)">
<xsl:text> xmlns="</xsl:text>
<xsl:value-of select="namespace-uri()"/>
<xsl:text>"</xsl:text>
</xsl:if>
<xsl:apply-templates mode="dump" select="@*"/>
<xsl:choose>
<xsl:when test="*|text()[string-length(normalize-space(.))!=0]">
<xsl:text>></xsl:text>
<xsl:choose>
<xsl:when test="*">
<xsl:text>
</xsl:text>
<xsl:apply-templates mode="dump" select="*|text()[string-length(normalize-space(.))!=0]">
<xsl:with-param name="indent" select="$indent + 2"/>
</xsl:apply-templates>
<xsl:apply-templates mode="indent" select=".">
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="dump" select="text()[string-length(normalize-space(.))!=0]"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text></</xsl:text>
<xsl:value-of select="local-name()"/>
<xsl:text>>
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>/>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template mode="dump" match="@*">
<xsl:text> </xsl:text>
<xsl:value-of select="local-name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:template mode="dump" match="text()">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template mode="indent" match="*">
<xsl:param name="indent" select="0"/>
<xsl:if test="$indent > 0">
<xsl:text> </xsl:text>
<xsl:apply-templates mode="indent" select=".">
<xsl:with-param name="indent" select="$indent - 1"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
</xsl:transform>