rdfobjects 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -0
- data/README +103 -0
- data/lib/rdf_objects/curies.rb +62 -0
- data/lib/rdf_objects/data_types.rb +57 -0
- data/lib/rdf_objects/http_client.rb +55 -0
- data/lib/rdf_objects/parsers.rb +274 -0
- data/lib/rdf_objects/rdf_resource.rb +216 -0
- data/lib/rdf_objects/serializers.rb +7 -0
- data/lib/rdf_objects.rb +11 -0
- data/lib/xsl/RDFa2RDFXML.xsl +677 -0
- data/lib/xsl/rdf2nt.xsl +308 -0
- data/lib/xsl/rdf2r3x.xsl +219 -0
- metadata +96 -0
@@ -0,0 +1,677 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<stylesheet
|
3
|
+
xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" version="1.0"
|
4
|
+
xmlns:h ="http://www.w3.org/1999/xhtml"
|
5
|
+
xmlns ="http://www.w3.org/1999/XSL/Transform"
|
6
|
+
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
7
|
+
|
8
|
+
|
9
|
+
<!-- Version 0.21 by Fabien.Gandon@sophia.inria.fr -->
|
10
|
+
<!-- This software is distributed under either the CeCILL-C license or the GNU Lesser General Public License version 3 license. -->
|
11
|
+
<!-- This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License -->
|
12
|
+
<!-- as published by the Free Software Foundation version 3 of the License or under the terms of the CeCILL-C license. -->
|
13
|
+
<!-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied -->
|
14
|
+
<!-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -->
|
15
|
+
<!-- See the GNU Lesser General Public License version 3 at http://www.gnu.org/licenses/ -->
|
16
|
+
<!-- and the CeCILL-C license at http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html for more details -->
|
17
|
+
|
18
|
+
|
19
|
+
<output indent="yes" method="xml" media-type="application/rdf+xml" encoding="UTF-8" omit-xml-declaration="yes"/>
|
20
|
+
|
21
|
+
<!-- base of the current HTML doc -->
|
22
|
+
<variable name='html_base' select="//*/h:head/h:base[position()=1]/@href"/>
|
23
|
+
|
24
|
+
<!-- default HTML vocabulary namespace -->
|
25
|
+
<variable name='default_voc' select="'http://www.w3.org/1999/xhtml/vocab#'"/>
|
26
|
+
|
27
|
+
<!-- url of the current XHTML page if provided by the XSLT engine -->
|
28
|
+
<param name='url' select="''"/>
|
29
|
+
|
30
|
+
<!-- this contains the URL of the source document whether it was provided by the base or as a parameter e.g. http://example.org/bla/file.html-->
|
31
|
+
<variable name='this' >
|
32
|
+
<choose>
|
33
|
+
<when test="string-length($html_base)>0"><value-of select="$html_base"/></when>
|
34
|
+
<otherwise><value-of select="$url"/></otherwise>
|
35
|
+
</choose>
|
36
|
+
</variable>
|
37
|
+
|
38
|
+
<!-- this_location contains the location the source document e.g. http://example.org/bla/ -->
|
39
|
+
<variable name='this_location' >
|
40
|
+
<call-template name="get-location"><with-param name="url" select="$this"/></call-template>
|
41
|
+
</variable>
|
42
|
+
|
43
|
+
<!-- this_root contains the root location of the source document e.g. http://example.org/ -->
|
44
|
+
<variable name='this_root' >
|
45
|
+
<call-template name="get-root"><with-param name="url" select="$this"/></call-template>
|
46
|
+
</variable>
|
47
|
+
|
48
|
+
|
49
|
+
<!-- templates for parsing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
50
|
+
|
51
|
+
<!--Start the RDF generation-->
|
52
|
+
<template match="/">
|
53
|
+
<rdf:RDF xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
|
54
|
+
<apply-templates mode="rdf2rdfxml" /> <!-- the mode is used to ease integration with other XSLT templates -->
|
55
|
+
</rdf:RDF>
|
56
|
+
</template>
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
<!-- match RDFa element -->
|
61
|
+
<template match="*[attribute::property or attribute::rel or attribute::rev or attribute::typeof]" mode="rdf2rdfxml" >
|
62
|
+
|
63
|
+
<!-- identify suject -->
|
64
|
+
<variable name="subject"><call-template name="subject"/></variable>
|
65
|
+
|
66
|
+
|
67
|
+
<!-- do we have object properties? -->
|
68
|
+
<if test="string-length(@rel)>0 or string-length(@rev)>0">
|
69
|
+
<variable name="object"> <!-- identify the object(s) -->
|
70
|
+
<choose>
|
71
|
+
<when test="@resource">
|
72
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="@resource"/></call-template>
|
73
|
+
</when>
|
74
|
+
<when test="@href">
|
75
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="@href"/></call-template>
|
76
|
+
</when>
|
77
|
+
<when test="descendant::*[attribute::about or attribute::src or attribute::typeof or
|
78
|
+
attribute::href or attribute::resource or
|
79
|
+
attribute::rel or attribute::rev or attribute::property]">
|
80
|
+
<call-template name="recurse-objects"/>
|
81
|
+
</when>
|
82
|
+
<otherwise>
|
83
|
+
<call-template name="self-curie-or-uri"><with-param name="node" select="."/></call-template>
|
84
|
+
</otherwise>
|
85
|
+
</choose>
|
86
|
+
</variable>
|
87
|
+
|
88
|
+
<call-template name="relrev">
|
89
|
+
<with-param name="subject" select="$subject"/>
|
90
|
+
<with-param name="object" select="$object"/>
|
91
|
+
</call-template>
|
92
|
+
|
93
|
+
</if>
|
94
|
+
|
95
|
+
|
96
|
+
<!-- do we have data properties ? -->
|
97
|
+
<if test="string-length(@property)>0">
|
98
|
+
|
99
|
+
<!-- identify language -->
|
100
|
+
<variable name="language" select="string(ancestor-or-self::*/attribute::xml:lang[position()=1])" />
|
101
|
+
|
102
|
+
<variable name="expended-pro"><call-template name="expand-ns"><with-param name="qname" select="@property"/></call-template></variable>
|
103
|
+
|
104
|
+
<choose>
|
105
|
+
<when test="@content"> <!-- there is a specific content -->
|
106
|
+
<call-template name="property">
|
107
|
+
<with-param name="subject" select ="$subject" />
|
108
|
+
<with-param name="object" select ="@content" />
|
109
|
+
<with-param name="datatype" >
|
110
|
+
<choose>
|
111
|
+
<when test="@datatype='' or not(@datatype)"></when> <!-- enforcing plain literal -->
|
112
|
+
<otherwise><call-template name="expand-ns"><with-param name="qname" select="@datatype"/></call-template></otherwise>
|
113
|
+
</choose>
|
114
|
+
</with-param>
|
115
|
+
<with-param name="predicate" select ="@property"/>
|
116
|
+
<with-param name="attrib" select ="'true'"/>
|
117
|
+
<with-param name="language" select ="$language"/>
|
118
|
+
</call-template>
|
119
|
+
</when>
|
120
|
+
<when test="not(*)"> <!-- there no specific content but there are no children elements in the content -->
|
121
|
+
<call-template name="property">
|
122
|
+
<with-param name="subject" select ="$subject" />
|
123
|
+
<with-param name="object" select ="." />
|
124
|
+
<with-param name="datatype">
|
125
|
+
<choose>
|
126
|
+
<when test="@datatype='' or not(@datatype)"></when> <!-- enforcing plain literal -->
|
127
|
+
<otherwise><call-template name="expand-ns"><with-param name="qname" select="@datatype"/></call-template></otherwise>
|
128
|
+
</choose>
|
129
|
+
</with-param>
|
130
|
+
<with-param name="predicate" select ="@property"/>
|
131
|
+
<with-param name="attrib" select ="'true'"/>
|
132
|
+
<with-param name="language" select ="$language"/>
|
133
|
+
</call-template>
|
134
|
+
</when>
|
135
|
+
<otherwise> <!-- there is no specific content; we use the value of element -->
|
136
|
+
<call-template name="property">
|
137
|
+
<with-param name="subject" select ="$subject" />
|
138
|
+
<with-param name="object" select ="." />
|
139
|
+
<with-param name="datatype">
|
140
|
+
<choose>
|
141
|
+
<when test="@datatype='' or not(@datatype)">http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral</when> <!-- enforcing XML literal -->
|
142
|
+
<otherwise><call-template name="expand-ns"><with-param name="qname" select="@datatype"/></call-template></otherwise>
|
143
|
+
</choose>
|
144
|
+
</with-param>
|
145
|
+
<with-param name="predicate" select ="@property"/>
|
146
|
+
<with-param name="attrib" select ="'false'"/>
|
147
|
+
<with-param name="language" select ="$language"/>
|
148
|
+
</call-template>
|
149
|
+
</otherwise>
|
150
|
+
</choose>
|
151
|
+
</if>
|
152
|
+
|
153
|
+
<!-- do we have classes ? -->
|
154
|
+
<if test="@typeof">
|
155
|
+
<call-template name="class">
|
156
|
+
<with-param name="resource"><call-template name="self-curie-or-uri"><with-param name="node" select="."/></call-template></with-param>
|
157
|
+
<with-param name="class" select="@typeof"/>
|
158
|
+
</call-template>
|
159
|
+
</if>
|
160
|
+
|
161
|
+
<apply-templates mode="rdf2rdfxml" />
|
162
|
+
|
163
|
+
</template>
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
<!-- named templates to process URIs and token lists - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
168
|
+
|
169
|
+
<!-- tokenize a string using space as a delimiter -->
|
170
|
+
<template name="tokenize">
|
171
|
+
<param name="string" />
|
172
|
+
<if test="string-length($string)>0">
|
173
|
+
<choose>
|
174
|
+
<when test="contains($string,' ')">
|
175
|
+
<value-of select="normalize-space(substring-before($string,' '))"/>
|
176
|
+
<call-template name="tokenize"><with-param name="string" select="normalize-space(substring-after($string,' '))"/></call-template>
|
177
|
+
</when>
|
178
|
+
<otherwise><value-of select="$string"/></otherwise>
|
179
|
+
</choose>
|
180
|
+
</if>
|
181
|
+
</template>
|
182
|
+
|
183
|
+
<!-- get file location from URL -->
|
184
|
+
<template name="get-location">
|
185
|
+
<param name="url" />
|
186
|
+
<if test="string-length($url)>0 and contains($url,'/')">
|
187
|
+
<value-of select="concat(substring-before($url,'/'),'/')"/>
|
188
|
+
<call-template name="get-location"><with-param name="url" select="substring-after($url,'/')"/></call-template>
|
189
|
+
</if>
|
190
|
+
</template>
|
191
|
+
|
192
|
+
<!-- get root location from URL -->
|
193
|
+
<template name="get-root">
|
194
|
+
<param name="url" />
|
195
|
+
<choose>
|
196
|
+
<when test="contains($url,'//')">
|
197
|
+
<value-of select="concat(substring-before($url,'//'),'//',substring-before(substring-after($url,'//'),'/'),'/')"/>
|
198
|
+
</when>
|
199
|
+
<otherwise>UNKNOWN ROOT</otherwise>
|
200
|
+
</choose>
|
201
|
+
</template>
|
202
|
+
|
203
|
+
<!-- return namespace of a qname -->
|
204
|
+
<template name="return-ns" >
|
205
|
+
<param name="qname" />
|
206
|
+
<variable name="ns_prefix" select="substring-before($qname,':')" />
|
207
|
+
<if test="string-length($ns_prefix)>0"> <!-- prefix must be explicit -->
|
208
|
+
<variable name="name" select="substring-after($qname,':')" />
|
209
|
+
<value-of select="ancestor-or-self::*/namespace::*[name()=$ns_prefix][position()=1]" />
|
210
|
+
</if>
|
211
|
+
<if test="string-length($ns_prefix)=0 and ancestor-or-self::*/namespace::*[name()=''][position()=1]"> <!-- no prefix -->
|
212
|
+
<variable name="name" select="substring-after($qname,':')" />
|
213
|
+
<value-of select="ancestor-or-self::*/namespace::*[name()=''][position()=1]" />
|
214
|
+
</if>
|
215
|
+
</template>
|
216
|
+
|
217
|
+
|
218
|
+
<!-- expand namespace of a qname -->
|
219
|
+
<template name="expand-ns" >
|
220
|
+
<param name="qname" />
|
221
|
+
<variable name="ns_prefix" select="substring-before($qname,':')" />
|
222
|
+
<if test="string-length($ns_prefix)>0"> <!-- prefix must be explicit -->
|
223
|
+
<variable name="name" select="substring-after($qname,':')" />
|
224
|
+
<variable name="ns_uri" select="ancestor-or-self::*/namespace::*[name()=$ns_prefix][position()=1]" />
|
225
|
+
<value-of select="concat($ns_uri,$name)" />
|
226
|
+
</if>
|
227
|
+
<if test="string-length($ns_prefix)=0 and ancestor-or-self::*/namespace::*[name()=''][position()=1]"> <!-- no prefix -->
|
228
|
+
<variable name="name" select="substring-after($qname,':')" />
|
229
|
+
<variable name="ns_uri" select="ancestor-or-self::*/namespace::*[name()=''][position()=1]" />
|
230
|
+
<value-of select="concat($ns_uri,$name)" />
|
231
|
+
</if>
|
232
|
+
</template>
|
233
|
+
|
234
|
+
<!-- determines the CURIE / URI of a node -->
|
235
|
+
<template name="self-curie-or-uri" >
|
236
|
+
<param name="node" />
|
237
|
+
<choose>
|
238
|
+
<when test="$node/attribute::about"> <!-- we have an about attribute to extend -->
|
239
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$node/attribute::about"/></call-template>
|
240
|
+
</when>
|
241
|
+
<when test="$node/attribute::src"> <!-- we have an src attribute to extend -->
|
242
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$node/attribute::src"/></call-template>
|
243
|
+
</when>
|
244
|
+
<when test="$node/attribute::resource and not($node/attribute::rel or $node/attribute::rev)"> <!-- enforcing the resource as subject if no rel or rev -->
|
245
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$node/attribute::resource"/></call-template>
|
246
|
+
</when>
|
247
|
+
<when test="$node/attribute::href and not($node/attribute::rel or $node/attribute::rev)"> <!-- enforcing the href as subject if no rel or rev -->
|
248
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$node/attribute::href"/></call-template>
|
249
|
+
</when>
|
250
|
+
<when test="$node/self::h:head or $node/self::h:body or $node/self::h:html"><value-of select="$this"/></when> <!-- enforcing the doc as subject -->
|
251
|
+
<when test="$node/attribute::id"> <!-- we have an id attribute to extend -->
|
252
|
+
<value-of select="concat($this,'#',$node/attribute::id)" />
|
253
|
+
</when>
|
254
|
+
<otherwise>blank:node:<value-of select="generate-id($node)" /></otherwise>
|
255
|
+
</choose>
|
256
|
+
</template>
|
257
|
+
|
258
|
+
|
259
|
+
<!-- expand CURIE / URI -->
|
260
|
+
<template name="expand-curie-or-uri" >
|
261
|
+
<param name="curie_or_uri" />
|
262
|
+
<choose>
|
263
|
+
<when test="starts-with($curie_or_uri,'[_:')"> <!-- we have a CURIE blank node -->
|
264
|
+
<value-of select="concat('blank:node:',substring-after(substring-before($curie_or_uri,']'),'[_:'))"/>
|
265
|
+
</when>
|
266
|
+
<when test="starts-with($curie_or_uri,'[')"> <!-- we have a CURIE between square brackets -->
|
267
|
+
<call-template name="expand-ns"><with-param name="qname" select="substring-after(substring-before($curie_or_uri,']'),'[')"/></call-template>
|
268
|
+
</when>
|
269
|
+
<when test="starts-with($curie_or_uri,'#')"> <!-- we have an anchor -->
|
270
|
+
<value-of select="concat($this,$curie_or_uri)" />
|
271
|
+
</when>
|
272
|
+
<when test="string-length($curie_or_uri)=0"> <!-- empty anchor means the document itself -->
|
273
|
+
<value-of select="$this" />
|
274
|
+
</when>
|
275
|
+
<when test="not(starts-with($curie_or_uri,'[')) and contains($curie_or_uri,':')"> <!-- it is a URI -->
|
276
|
+
<value-of select="$curie_or_uri" />
|
277
|
+
</when>
|
278
|
+
<when test="not(contains($curie_or_uri,'://')) and not(starts-with($curie_or_uri,'/'))"> <!-- relative URL -->
|
279
|
+
<value-of select="concat($this_location,$curie_or_uri)" />
|
280
|
+
</when>
|
281
|
+
<when test="not(contains($curie_or_uri,'://')) and (starts-with($curie_or_uri,'/'))"> <!-- URL from root domain -->
|
282
|
+
<value-of select="concat($this_root,substring-after($curie_or_uri,'/'))" />
|
283
|
+
</when>
|
284
|
+
<otherwise>UNKNOWN CURIE URI</otherwise>
|
285
|
+
</choose>
|
286
|
+
</template>
|
287
|
+
|
288
|
+
<!-- returns the first token in a list separated by spaces -->
|
289
|
+
<template name="get-first-token">
|
290
|
+
<param name="tokens" />
|
291
|
+
<if test="string-length($tokens)>0">
|
292
|
+
<choose>
|
293
|
+
<when test="contains($tokens,' ')">
|
294
|
+
<value-of select="normalize-space(substring-before($tokens,' '))"/>
|
295
|
+
</when>
|
296
|
+
<otherwise><value-of select="$tokens" /></otherwise>
|
297
|
+
</choose>
|
298
|
+
</if>
|
299
|
+
</template>
|
300
|
+
|
301
|
+
<!-- returns the namespace for an object property -->
|
302
|
+
<template name="get-relrev-ns">
|
303
|
+
<param name="qname" />
|
304
|
+
<variable name="ns_prefix" select="substring-before(translate($qname,'[]',''),':')" />
|
305
|
+
<choose>
|
306
|
+
<when test="string-length($ns_prefix)>0">
|
307
|
+
<call-template name="return-ns"><with-param name="qname" select="$qname"/></call-template>
|
308
|
+
</when>
|
309
|
+
<!-- returns default_voc if the predicate is a reserved value -->
|
310
|
+
<otherwise>
|
311
|
+
<variable name="is-reserved"><call-template name="check-reserved"><with-param name="nonprefixed"><call-template name="no-leading-colon"><with-param name="name" select="$qname"/></call-template></with-param></call-template></variable>
|
312
|
+
<if test="$is-reserved='true'"><value-of select="$default_voc" /></if>
|
313
|
+
</otherwise>
|
314
|
+
</choose>
|
315
|
+
</template>
|
316
|
+
|
317
|
+
<!-- returns the namespace for a data property -->
|
318
|
+
<template name="get-property-ns">
|
319
|
+
<param name="qname" />
|
320
|
+
<variable name="ns_prefix" select="substring-before(translate($qname,'[]',''),':')" />
|
321
|
+
<choose>
|
322
|
+
<when test="string-length($ns_prefix)>0">
|
323
|
+
<call-template name="return-ns"><with-param name="qname" select="$qname"/></call-template>
|
324
|
+
</when>
|
325
|
+
<!-- returns default_voc otherwise -->
|
326
|
+
<otherwise><value-of select="$default_voc" /></otherwise>
|
327
|
+
</choose>
|
328
|
+
</template>
|
329
|
+
|
330
|
+
<!-- returns the qname for a predicate -->
|
331
|
+
<template name="get-predicate-name">
|
332
|
+
<param name="qname" />
|
333
|
+
<variable name="clean_name" select="translate($qname,'[]','')" />
|
334
|
+
<call-template name="no-leading-colon"><with-param name="name" select="$clean_name"/></call-template>
|
335
|
+
</template>
|
336
|
+
|
337
|
+
<!-- no leading colon -->
|
338
|
+
<template name="no-leading-colon">
|
339
|
+
<param name="name" />
|
340
|
+
<choose>
|
341
|
+
<when test="starts-with($name,':')"> <!-- remove leading colons -->
|
342
|
+
<value-of select="substring-after($name,':')" />
|
343
|
+
</when>
|
344
|
+
<otherwise><value-of select="$name" /></otherwise>
|
345
|
+
</choose>
|
346
|
+
</template>
|
347
|
+
|
348
|
+
<!-- check if a predicate is reserved -->
|
349
|
+
<template name="check-reserved">
|
350
|
+
<param name="nonprefixed" />
|
351
|
+
<choose>
|
352
|
+
<when test="$nonprefixed='alternate' or $nonprefixed='appendix' or $nonprefixed='bookmark' or $nonprefixed='cite'">true</when>
|
353
|
+
<when test="$nonprefixed='chapter' or $nonprefixed='contents' or $nonprefixed='copyright' or $nonprefixed='first'">true</when>
|
354
|
+
<when test="$nonprefixed='glossary' or $nonprefixed='help' or $nonprefixed='icon' or $nonprefixed='index'">true</when>
|
355
|
+
<when test="$nonprefixed='last' or $nonprefixed='license' or $nonprefixed='meta' or $nonprefixed='next'">true</when>
|
356
|
+
<when test="$nonprefixed='p3pv1' or $nonprefixed='prev' or $nonprefixed='role' or $nonprefixed='section'">true</when>
|
357
|
+
<when test="$nonprefixed='stylesheet' or $nonprefixed='subsection' or $nonprefixed='start' or $nonprefixed='top'">true</when>
|
358
|
+
<when test="$nonprefixed='up'">true</when>
|
359
|
+
<when test="$nonprefixed='made' or $nonprefixed='previous' or $nonprefixed='search'">true</when> <!-- added because they are frequent -->
|
360
|
+
<otherwise>false</otherwise>
|
361
|
+
</choose>
|
362
|
+
</template>
|
363
|
+
|
364
|
+
<!-- named templates to generate RDF - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
|
365
|
+
|
366
|
+
<template name="recursive-copy"> <!-- full copy -->
|
367
|
+
<copy><for-each select="node()|attribute::* "><call-template name="recursive-copy" /></for-each></copy>
|
368
|
+
</template>
|
369
|
+
|
370
|
+
|
371
|
+
<template name="subject"> <!-- determines current subject -->
|
372
|
+
<choose>
|
373
|
+
|
374
|
+
<!-- current node is a meta or a link in the head and with no about attribute -->
|
375
|
+
<when test="(self::h:link or self::h:meta) and ( ancestor::h:head ) and not(attribute::about)">
|
376
|
+
<value-of select="$this"/>
|
377
|
+
</when>
|
378
|
+
|
379
|
+
<!-- an attribute about was specified on the node -->
|
380
|
+
<when test="self::*/attribute::about">
|
381
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="@about"/></call-template>
|
382
|
+
</when>
|
383
|
+
|
384
|
+
<!-- an attribute src was specified on the node -->
|
385
|
+
<when test="self::*/attribute::src">
|
386
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="@src"/></call-template>
|
387
|
+
</when>
|
388
|
+
|
389
|
+
|
390
|
+
<!-- an attribute typeof was specified on the node -->
|
391
|
+
<when test="self::*/attribute::typeof">
|
392
|
+
<call-template name="self-curie-or-uri"><with-param name="node" select="."/></call-template>
|
393
|
+
</when>
|
394
|
+
|
395
|
+
<!-- current node is a meta or a link in the body and with no about attribute -->
|
396
|
+
<when test="(self::h:link or self::h:meta) and not( ancestor::h:head ) and not(attribute::about)">
|
397
|
+
<call-template name="self-curie-or-uri"><with-param name="node" select="parent::*"/></call-template>
|
398
|
+
</when>
|
399
|
+
|
400
|
+
<!-- an about was specified on its parent or the parent had a rel or a rev attribute but no href or an typeof. -->
|
401
|
+
<when test="ancestor::*[attribute::about or attribute::src or attribute::typeof or attribute::resource or attribute::href or attribute::rel or attribute::rev][position()=1]">
|
402
|
+
<variable name="selected_ancestor" select="ancestor::*[attribute::about or attribute::src or attribute::typeof or attribute::resource or attribute::href or attribute::rel or attribute::rev][position()=1]"/>
|
403
|
+
<choose>
|
404
|
+
<when test="$selected_ancestor[(attribute::rel or attribute::rev) and not (attribute::resource or attribute::href)]">
|
405
|
+
<value-of select="concat('blank:node:INSIDE_',generate-id($selected_ancestor))"/>
|
406
|
+
</when>
|
407
|
+
<when test="$selected_ancestor/attribute::about">
|
408
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$selected_ancestor/attribute::about"/></call-template>
|
409
|
+
</when>
|
410
|
+
<when test="$selected_ancestor/attribute::src">
|
411
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$selected_ancestor/attribute::src"/></call-template>
|
412
|
+
</when>
|
413
|
+
<when test="$selected_ancestor/attribute::resource">
|
414
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$selected_ancestor/attribute::resource"/></call-template>
|
415
|
+
</when>
|
416
|
+
<when test="$selected_ancestor/attribute::href">
|
417
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="$selected_ancestor/attribute::href"/></call-template>
|
418
|
+
</when>
|
419
|
+
<otherwise>
|
420
|
+
<call-template name="self-curie-or-uri"><with-param name="node" select="$selected_ancestor"/></call-template>
|
421
|
+
</otherwise>
|
422
|
+
</choose>
|
423
|
+
</when>
|
424
|
+
|
425
|
+
<otherwise> <!-- it must be about the current document -->
|
426
|
+
<value-of select="$this"/>
|
427
|
+
</otherwise>
|
428
|
+
|
429
|
+
</choose>
|
430
|
+
</template>
|
431
|
+
|
432
|
+
<!-- recursive call for object(s) of object properties -->
|
433
|
+
<template name="recurse-objects" >
|
434
|
+
<xsl:for-each select="child::*">
|
435
|
+
<choose>
|
436
|
+
<when test="attribute::about or attribute::src"> <!-- there is a known resource -->
|
437
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="attribute::about | attribute::src"/></call-template><text> </text>
|
438
|
+
</when>
|
439
|
+
<when test="(attribute::resource or attribute::href) and ( not (attribute::rel or attribute::rev or attribute::property))"> <!-- there is an incomplet triple -->
|
440
|
+
<call-template name="expand-curie-or-uri"><with-param name="curie_or_uri" select="attribute::resource | attribute::href"/></call-template><text> </text>
|
441
|
+
</when>
|
442
|
+
<when test="attribute::typeof and not (attribute::about)"> <!-- there is an implicit resource -->
|
443
|
+
<call-template name="self-curie-or-uri"><with-param name="node" select="."/></call-template><text> </text>
|
444
|
+
</when>
|
445
|
+
<when test="attribute::rel or attribute::rev or attribute::property"> <!-- there is an implicit resource -->
|
446
|
+
<if test="not (preceding-sibling::*[attribute::rel or attribute::rev or attribute::property])"> <!-- generate the triple only once -->
|
447
|
+
<call-template name="subject"/><text> </text>
|
448
|
+
</if>
|
449
|
+
</when>
|
450
|
+
<otherwise> <!-- nothing at that level thus consider children -->
|
451
|
+
<call-template name="recurse-objects"/>
|
452
|
+
</otherwise>
|
453
|
+
</choose>
|
454
|
+
</xsl:for-each>
|
455
|
+
</template>
|
456
|
+
|
457
|
+
<!-- generate recursive call for multiple objects in rel or rev -->
|
458
|
+
<template name="relrev" >
|
459
|
+
<param name="subject" />
|
460
|
+
<param name="object" />
|
461
|
+
|
462
|
+
<!-- test for multiple predicates -->
|
463
|
+
<variable name="single-object"><call-template name="get-first-token"><with-param name="tokens" select="$object"/></call-template></variable>
|
464
|
+
|
465
|
+
<if test="string-length(@rel)>0">
|
466
|
+
<call-template name="relation">
|
467
|
+
<with-param name="subject" select ="$subject" />
|
468
|
+
<with-param name="object" select ="$single-object" />
|
469
|
+
<with-param name="predicate" select ="@rel"/>
|
470
|
+
</call-template>
|
471
|
+
</if>
|
472
|
+
|
473
|
+
<if test="string-length(@rev)>0">
|
474
|
+
<call-template name="relation">
|
475
|
+
<with-param name="subject" select ="$single-object" />
|
476
|
+
<with-param name="object" select ="$subject" />
|
477
|
+
<with-param name="predicate" select ="@rev"/>
|
478
|
+
</call-template>
|
479
|
+
</if>
|
480
|
+
|
481
|
+
<!-- recursive call for multiple predicates -->
|
482
|
+
<variable name="other-objects" select="normalize-space(substring-after($object,' '))" />
|
483
|
+
<if test="string-length($other-objects)>0">
|
484
|
+
<call-template name="relrev">
|
485
|
+
<with-param name="subject" select="$subject"/>
|
486
|
+
<with-param name="object" select="$other-objects"/>
|
487
|
+
</call-template>
|
488
|
+
</if>
|
489
|
+
|
490
|
+
</template>
|
491
|
+
|
492
|
+
|
493
|
+
<!-- generate an RDF statement for a relation -->
|
494
|
+
<template name="relation" >
|
495
|
+
<param name="subject" />
|
496
|
+
<param name="predicate" />
|
497
|
+
<param name="object" />
|
498
|
+
|
499
|
+
<!-- test for multiple predicates -->
|
500
|
+
<variable name="single-predicate"><call-template name="get-first-token"><with-param name="tokens" select="$predicate"/></call-template></variable>
|
501
|
+
|
502
|
+
<!-- get namespace of the predicate -->
|
503
|
+
<variable name="predicate-ns"><call-template name="get-relrev-ns"><with-param name="qname" select="$single-predicate"/></call-template></variable>
|
504
|
+
|
505
|
+
<!-- get name of the predicate -->
|
506
|
+
<variable name="predicate-name"><call-template name="get-predicate-name"><with-param name="qname" select="$single-predicate"/></call-template></variable>
|
507
|
+
|
508
|
+
<choose>
|
509
|
+
<when test="string-length($predicate-ns)>0"> <!-- there is a known namespace for the predicate -->
|
510
|
+
<element name = "rdf:Description" namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
511
|
+
<choose>
|
512
|
+
<when test="starts-with($subject,'blank:node:')"><attribute name="rdf:nodeID"><value-of select="substring-after($subject,'blank:node:')" /></attribute></when>
|
513
|
+
<otherwise><attribute name="rdf:about"><value-of select="$subject" /></attribute></otherwise>
|
514
|
+
</choose>
|
515
|
+
<element name = "{$predicate-name}" namespace="{$predicate-ns}">
|
516
|
+
<choose>
|
517
|
+
<when test="starts-with($object,'blank:node:')"><attribute name="rdf:nodeID"><value-of select="substring-after($object,'blank:node:')" /></attribute></when>
|
518
|
+
<otherwise><attribute name="rdf:resource"><value-of select="$object" /></attribute></otherwise>
|
519
|
+
</choose>
|
520
|
+
</element>
|
521
|
+
</element>
|
522
|
+
</when>
|
523
|
+
<otherwise> <!-- no namespace generate a comment for debug -->
|
524
|
+
<xsl:comment>No namespace for the rel or rev value ; could not produce the triple for: <value-of select="$subject" /> - <value-of select="$single-predicate" /> - <value-of select="$object" /></xsl:comment>
|
525
|
+
</otherwise>
|
526
|
+
</choose>
|
527
|
+
|
528
|
+
<!-- recursive call for multiple predicates -->
|
529
|
+
<variable name="other-predicates" select="normalize-space(substring-after($predicate,' '))" />
|
530
|
+
<if test="string-length($other-predicates)>0">
|
531
|
+
<call-template name="relation">
|
532
|
+
<with-param name="subject" select="$subject"/>
|
533
|
+
<with-param name="predicate" select="$other-predicates"/>
|
534
|
+
<with-param name="object" select="$object"/>
|
535
|
+
</call-template>
|
536
|
+
</if>
|
537
|
+
|
538
|
+
</template>
|
539
|
+
|
540
|
+
|
541
|
+
<!-- generate an RDF statement for a property -->
|
542
|
+
<template name="property" >
|
543
|
+
<param name="subject" />
|
544
|
+
<param name="predicate" />
|
545
|
+
<param name="object" />
|
546
|
+
<param name="datatype" />
|
547
|
+
<param name="attrib" /> <!-- is the content from an attribute ? true /false -->
|
548
|
+
<param name="language" />
|
549
|
+
|
550
|
+
<!-- test for multiple predicates -->
|
551
|
+
<variable name="single-predicate"><call-template name="get-first-token"><with-param name="tokens" select="$predicate"/></call-template></variable>
|
552
|
+
|
553
|
+
<!-- get namespace of the predicate -->
|
554
|
+
<variable name="predicate-ns"><call-template name="get-property-ns"><with-param name="qname" select="$single-predicate"/></call-template></variable>
|
555
|
+
|
556
|
+
|
557
|
+
<!-- get name of the predicate -->
|
558
|
+
<variable name="predicate-name"><call-template name="get-predicate-name"><with-param name="qname" select="$single-predicate"/></call-template></variable>
|
559
|
+
|
560
|
+
<choose>
|
561
|
+
<when test="string-length($predicate-ns)>0"> <!-- there is a known namespace for the predicate -->
|
562
|
+
<element name = "rdf:Description" namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
563
|
+
<choose>
|
564
|
+
<when test="starts-with($subject,'blank:node:')"><attribute name="rdf:nodeID"><value-of select="substring-after($subject,'blank:node:')" /></attribute></when>
|
565
|
+
<otherwise><attribute name="rdf:about"><value-of select="$subject" /></attribute></otherwise>
|
566
|
+
</choose>
|
567
|
+
<element name = "{$predicate-name}" namespace="{$predicate-ns}">
|
568
|
+
<if test="string-length($language)>0"><attribute name="xml:lang"><value-of select="$language" /></attribute></if>
|
569
|
+
<choose>
|
570
|
+
<when test="$datatype='http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral'">
|
571
|
+
<choose>
|
572
|
+
<when test="$attrib='true'"> <!-- content is in an attribute -->
|
573
|
+
<attribute name="rdf:datatype"><value-of select="$datatype" /></attribute>
|
574
|
+
<value-of select="normalize-space(string($object))" />
|
575
|
+
</when>
|
576
|
+
<otherwise> <!-- content is in the element and may include some tags -->
|
577
|
+
<!-- On a property element, only one of the attributes rdf:parseType or rdf:datatype is permitted.
|
578
|
+
<attribute name="rdf:datatype"><value-of select="$datatype" /></attribute> -->
|
579
|
+
<attribute name="rdf:parseType"><value-of select="'Literal'" /></attribute>
|
580
|
+
<for-each select="$object/node()">
|
581
|
+
<call-template name="recursive-copy" />
|
582
|
+
</for-each>
|
583
|
+
</otherwise>
|
584
|
+
</choose>
|
585
|
+
</when>
|
586
|
+
<when test="string-length($datatype)>0">
|
587
|
+
<!-- there is a datatype other than XMLLiteral -->
|
588
|
+
<attribute name="rdf:datatype"><value-of select="$datatype" /></attribute>
|
589
|
+
<choose>
|
590
|
+
<when test="$attrib='true'"> <!-- content is in an attribute -->
|
591
|
+
<value-of select="normalize-space(string($object))" />
|
592
|
+
</when>
|
593
|
+
<otherwise> <!-- content is in the text nodes of the element -->
|
594
|
+
<value-of select="normalize-space($object)" />
|
595
|
+
</otherwise>
|
596
|
+
</choose>
|
597
|
+
</when>
|
598
|
+
<otherwise> <!-- there is no datatype -->
|
599
|
+
<choose>
|
600
|
+
<when test="$attrib='true'"> <!-- content is in an attribute -->
|
601
|
+
<value-of select="normalize-space(string($object))" />
|
602
|
+
</when>
|
603
|
+
<otherwise> <!-- content is in the text nodes of the element -->
|
604
|
+
<attribute name="rdf:parseType"><value-of select="'Literal'" /></attribute>
|
605
|
+
<for-each select="$object/node()">
|
606
|
+
<call-template name="recursive-copy" />
|
607
|
+
</for-each>
|
608
|
+
</otherwise>
|
609
|
+
</choose>
|
610
|
+
</otherwise>
|
611
|
+
</choose>
|
612
|
+
</element>
|
613
|
+
</element>
|
614
|
+
</when>
|
615
|
+
<otherwise> <!-- generate a comment for debug -->
|
616
|
+
<xsl:comment>Could not produce the triple for: <value-of select="$subject" /> - <value-of select="$single-predicate" /> - <value-of select="$object" /></xsl:comment>
|
617
|
+
</otherwise>
|
618
|
+
</choose>
|
619
|
+
|
620
|
+
<!-- recursive call for multiple predicates -->
|
621
|
+
<variable name="other-predicates" select="normalize-space(substring-after($predicate,' '))" />
|
622
|
+
<if test="string-length($other-predicates)>0">
|
623
|
+
<call-template name="property">
|
624
|
+
<with-param name="subject" select="$subject"/>
|
625
|
+
<with-param name="predicate" select="$other-predicates"/>
|
626
|
+
<with-param name="object" select="$object"/>
|
627
|
+
<with-param name="datatype" select="$datatype"/>
|
628
|
+
<with-param name="attrib" select="$attrib"/>
|
629
|
+
<with-param name="language" select="$language"/>
|
630
|
+
</call-template>
|
631
|
+
</if>
|
632
|
+
|
633
|
+
</template>
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
<!-- generate an RDF statement for a class -->
|
638
|
+
<template name="class" >
|
639
|
+
<param name="resource" />
|
640
|
+
<param name="class" />
|
641
|
+
|
642
|
+
<!-- case multiple classes -->
|
643
|
+
<variable name="single-class"><call-template name="get-first-token"><with-param name="tokens" select="$class"/></call-template></variable>
|
644
|
+
|
645
|
+
<!-- get namespace of the class -->
|
646
|
+
<variable name="class-ns"><call-template name="return-ns"><with-param name="qname" select="$single-class"/></call-template></variable>
|
647
|
+
|
648
|
+
<if test="string-length($class-ns)>0"> <!-- we have a qname for the class -->
|
649
|
+
<variable name="expended-class"><call-template name="expand-ns"><with-param name="qname" select="$single-class"/></call-template></variable>
|
650
|
+
<element name = "rdf:Description" namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
651
|
+
<choose>
|
652
|
+
<when test="starts-with($resource,'blank:node:')"><attribute name="rdf:nodeID"><value-of select="substring-after($resource,'blank:node:')" /></attribute></when>
|
653
|
+
<otherwise><attribute name="rdf:about"><value-of select="$resource" /></attribute></otherwise>
|
654
|
+
</choose>
|
655
|
+
<element name = "rdf:type" namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
656
|
+
<attribute name="rdf:resource"><value-of select="$expended-class" /></attribute>
|
657
|
+
</element>
|
658
|
+
</element>
|
659
|
+
</if>
|
660
|
+
|
661
|
+
<!-- recursive call for multiple classes -->
|
662
|
+
<variable name="other-classes" select="normalize-space(substring-after($class,' '))" />
|
663
|
+
<if test="string-length($other-classes)>0">
|
664
|
+
<call-template name="class">
|
665
|
+
<with-param name="resource" select="$resource"/>
|
666
|
+
<with-param name="class" select="$other-classes"/>
|
667
|
+
</call-template>
|
668
|
+
</if>
|
669
|
+
|
670
|
+
</template>
|
671
|
+
|
672
|
+
|
673
|
+
<!-- ignore the rest of the DOM -->
|
674
|
+
<template match="text()|@*|*" mode="rdf2rdfxml"><apply-templates mode="rdf2rdfxml" /></template>
|
675
|
+
|
676
|
+
|
677
|
+
</stylesheet>
|