]> Lady’s Gitweb - Vocab/blob - transforms/data/rdf.xslt
Initial commit; initial set of vocabs
[Vocab] / transforms / data / rdf.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 © 2024 Lady [@ Ladys Computer].
8
9 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
10 If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
11 -->
12 <transform
13 xmlns="http://www.w3.org/1999/XSL/Transform"
14 xmlns:Vocab="urn:fdc:vocab.ladys.computer:20240731:ns"
15 xmlns:Vocabvocab="urn:fdc:vocab.ladys.computer:20240731:vocab:"
16 xmlns:html="http://www.w3.org/1999/xhtml"
17 xmlns:owl="http://www.w3.org/2002/07/owl#"
18 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
19 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
20 xmlns:shacl="http://www.w3.org/ns/shacl#"
21 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
22 exclude-result-prefixes="Vocab Vocabvocab"
23 version="1.0"
24 >
25 <书社:id>urn:fdc:vocab.ladys.computer:20240731:transforms:data:rdf.xslt</书社:id>
26 <key name="Vocab:name" match="owl:AnnotationProperty|owl:Class|owl:DatatypeProperty|owl:NamedIndividual|owl:ObjectProperty|rdfs:Datatype" use="@rdf:about|owl:sameAs/@rdf:resource"/>
27 <template name="Vocab:base">
28 <value-of select="//rdf:RDF//owl:Ontology/shacl:declare/shacl:namespace[preceding-sibling::shacl:prefix='']"/>
29 </template>
30 <template name="Vocab:prefix">
31 <param name="unprefixed" select="''"/>
32 <variable name="namespace" select="//rdf:RDF//owl:Ontology/shacl:declare/shacl:namespace[starts-with($unprefixed, string()) and string(preceding-sibling::shacl:prefix)!=''][1]"/>
33 <choose>
34 <when test="not($namespace)">
35 <value-of select="$unprefixed"/>
36 </when>
37 <otherwise>
38 <value-of select="$namespace/preceding-sibling::shacl:prefix"/>
39 <text>:</text>
40 <value-of select="substring-after($unprefixed, $namespace)"/>
41 </otherwise>
42 </choose>
43 </template>
44 <template match="rdf:RDF/*[@rdf:about and Vocabvocab:superClassOf]" priority="2">
45 <copy>
46 <apply-templates select="@*|node()[not(self::Vocabvocab:superClassOf)]"/>
47 </copy>
48 <for-each select="Vocabvocab:superClassOf/*[1]">
49 <copy>
50 <apply-templates select="@*|node()"/>
51 <element name="rdfs:subClassOf">
52 <attribute name="rdf:resource">
53 <value-of select="../../@rdf:about"/>
54 </attribute>
55 </element>
56 </copy>
57 </for-each>
58 </template>
59 <template match="@rdf:resource" priority="2">
60 <variable name="base-iri">
61 <call-template name="Vocab:base"/>
62 </variable>
63 <attribute name="rdf:resource">
64 <choose>
65 <when test="starts-with(., 'about:vocab?') and contains(., '=')">
66 <variable name="query" select="substring-after(., 'about:vocab?')"/>
67 <variable name="qterm" select="substring-before($query, '=')"/>
68 <variable name="subdir">
69 <choose>
70 <when test="$qterm='class'">
71 <text>classes/</text>
72 </when>
73 <when test="$qterm='property'">
74 <text>properties/</text>
75 </when>
76 <otherwise>
77 <text>individuals/</text>
78 </otherwise>
79 </choose>
80 </variable>
81 <variable name="match" select="//*[rdfs:isDefinedBy[starts-with(@rdf:resource, $base-iri) and substring-after(@rdf:resource, $base-iri)=concat($subdir, substring-after($query, '='), '.xhtml')]]"/>
82 <choose>
83 <when test="$match">
84 <value-of select="$match/@rdf:about"/>
85 </when>
86 <otherwise>
87 <value-of select="."/>
88 </otherwise>
89 </choose>
90 </when>
91 <otherwise>
92 <value-of select="."/>
93 </otherwise>
94 </choose>
95 </attribute>
96 </template>
97 <template match="html:a" priority="1">
98 <variable name="base-prefix">
99 <call-template name="Vocab:prefix">
100 <with-param name="unprefixed">
101 <call-template name="Vocab:base"/>
102 </with-param>
103 </call-template>
104 </variable>
105 <variable name="kind" select="@data-kind"/>
106 <variable name="linked-resource" select="key('Vocab:name', @href)[not($kind) or $kind='class' and (self::owl:Class or self::owl:Datatype) or $kind='property' and (self::owl:AnnotationProperty or self::owl:ObjectProperty or self::owl:DatatypeProperty) or $kind='individual' and self::owl:NamedIndividual][1]"/>
107 <copy>
108 <apply-templates select="@*[not(contains(' data-curie data-kind ', local-name()) and namespace-uri()='')]"/>
109 <choose>
110 <when test="$linked-resource">
111 <variable name="curie">
112 <call-template name="Vocab:prefix">
113 <with-param name="unprefixed" select="string(@href)"/>
114 </call-template>
115 </variable>
116 <variable name="localid">
117 <choose>
118 <when test="starts-with($curie, $base-prefix)">
119 <value-of select="substring-after($curie, $base-prefix)"/>
120 </when>
121 <otherwise>
122 <value-of select="$curie"/>
123 </otherwise>
124 </choose>
125 </variable>
126 <attribute name="data-curie">
127 <value-of select="$curie"/>
128 </attribute>
129 <attribute name="data-kind">
130 <choose>
131 <when test="@data-kind">
132 <value-of select="@data-kind"/>
133 </when>
134 <when test="$linked-resource[self::owl:Class or self::owl:Datatype]">
135 <text>class</text>
136 </when>
137 <when test="$linked-resource[self::owl:AnnotationProperty or self::owl:ObjectProperty or self::owl:DatatypeProperty]">
138 <text>property</text>
139 </when>
140 <otherwise>
141 <text>individual</text>
142 </otherwise>
143 </choose>
144 </attribute>
145 <choose>
146 <when test="html:code[not(preceding-sibling::node() or following-sibling::node())]">
147 <for-each select="$linked-resource">
148 <variable name="wrappername">
149 <choose>
150 <when test="substring($localid, 1, 1)='(' and substring($localid, string-length($localid), 1)=')'">
151 <text>cite</text>
152 </when>
153 <otherwise>
154 <text>span</text>
155 </otherwise>
156 </choose>
157 </variable>
158 <attribute name="title">
159 <value-of select="rdfs:label[1]"/>
160 <text> (</text>
161 <value-of select="$curie"/>
162 <text>)</text>
163 </attribute>
164 <element name="html:{$wrappername}">
165 <attribute name="lang">
166 <value-of select="rdfs:label[1]/@xml:lang"/>
167 </attribute>
168 <attribute name="xml:lang">
169 <value-of select="rdfs:label[1]/@xml:lang"/>
170 </attribute>
171 <value-of select="rdfs:label[1]"/>
172 </element>
173 </for-each>
174 </when>
175 <otherwise>
176 <apply-templates/>
177 </otherwise>
178 </choose>
179 </when>
180 <otherwise>
181 <apply-templates/>
182 </otherwise>
183 </choose>
184 </copy>
185 </template>
186 <template match="html:a/@href[starts-with(., '#footnote-')]">
187 <attribute name="href">
188 <text>#footnote-</text>
189 <value-of select="generate-id(ancestor::rdfs:comment//@id[string()=substring-after(current(), '#')])"/>
190 </attribute>
191 </template>
192 <template match="html:*/@id[starts-with(., 'footnote-')]" priority="1">
193 <attribute name="id">
194 <text>footnote-</text>
195 <value-of select="generate-id()"/>
196 </attribute>
197 </template>
198 </transform>
This page took 0.123402 seconds and 5 git commands to generate.