]> Lady’s Gitweb - Vocab/blob - transforms/rdf.xslt
Add airports; contact:nearestAirport
[Vocab] / transforms / rdf.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 © 2024–2025 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: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 match="/rdf:RDF" priority="2">
28 <copy>
29 <attribute name="xml:base">
30 <call-template name="Vocab:base"/>
31 </attribute>
32 <apply-templates select="@*[not(local-name()='base' and namespace-uri()='http://www.w3.org/XML/1998/namespace')]|node()"/>
33 </copy>
34 </template>
35 <template match="/rdf:RDF/*[@rdf:about and Vocabvocab:superClassOf]" priority="2">
36 <copy>
37 <apply-templates select="@*|node()[not(self::Vocabvocab:superClassOf)]"/>
38 </copy>
39 <for-each select="Vocabvocab:superClassOf/*[1]">
40 <copy>
41 <apply-templates select="@*|node()"/>
42 <element name="rdfs:subClassOf">
43 <attribute name="rdf:resource">
44 <value-of select="../../@rdf:about"/>
45 </attribute>
46 </element>
47 </copy>
48 </for-each>
49 </template>
50 <template match="/rdf:RDF//@rdf:resource" priority="2">
51 <variable name="base-iri">
52 <call-template name="Vocab:base"/>
53 </variable>
54 <attribute name="rdf:resource">
55 <choose>
56 <when test="starts-with(., 'about:vocab?') and contains(., '=')">
57 <variable name="query" select="substring-after(., 'about:vocab?')"/>
58 <variable name="qterm" select="substring-before($query, '=')"/>
59 <variable name="subdir">
60 <choose>
61 <when test="$qterm='class'">
62 <text>classes/</text>
63 </when>
64 <when test="$qterm='property'">
65 <text>properties/</text>
66 </when>
67 <otherwise>
68 <text>individuals/</text>
69 </otherwise>
70 </choose>
71 </variable>
72 <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')]]"/>
73 <choose>
74 <when test="$match">
75 <value-of select="$match/@rdf:about"/>
76 </when>
77 <otherwise>
78 <value-of select="."/>
79 </otherwise>
80 </choose>
81 </when>
82 <otherwise>
83 <value-of select="."/>
84 </otherwise>
85 </choose>
86 </attribute>
87 </template>
88 <template match="/rdf:RDF//html:a" priority="1">
89 <variable name="base-prefix">
90 <call-template name="Vocab:prefix">
91 <with-param name="unprefixed">
92 <call-template name="Vocab:base"/>
93 </with-param>
94 </call-template>
95 </variable>
96 <variable name="kind" select="@data-kind"/>
97 <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]"/>
98 <copy>
99 <apply-templates select="@*[not(contains(' data-curie data-kind ', local-name()) and namespace-uri()='')]"/>
100 <choose>
101 <when test="$linked-resource">
102 <variable name="curie">
103 <call-template name="Vocab:prefix">
104 <with-param name="unprefixed" select="string(@href)"/>
105 </call-template>
106 </variable>
107 <variable name="localid">
108 <choose>
109 <when test="starts-with($curie, $base-prefix)">
110 <value-of select="substring-after($curie, $base-prefix)"/>
111 </when>
112 <otherwise>
113 <value-of select="$curie"/>
114 </otherwise>
115 </choose>
116 </variable>
117 <attribute name="data-curie">
118 <value-of select="$curie"/>
119 </attribute>
120 <attribute name="data-kind">
121 <choose>
122 <when test="@data-kind">
123 <value-of select="@data-kind"/>
124 </when>
125 <when test="$linked-resource[self::owl:Class or self::owl:Datatype]">
126 <text>class</text>
127 </when>
128 <when test="$linked-resource[self::owl:AnnotationProperty or self::owl:ObjectProperty or self::owl:DatatypeProperty]">
129 <text>property</text>
130 </when>
131 <otherwise>
132 <text>individual</text>
133 </otherwise>
134 </choose>
135 </attribute>
136 <choose>
137 <when test="html:code[not(preceding-sibling::node() or following-sibling::node())]">
138 <for-each select="$linked-resource">
139 <variable name="wrappername">
140 <choose>
141 <when test="substring($localid, 1, 1)='(' and substring($localid, string-length($localid), 1)=')'">
142 <text>cite</text>
143 </when>
144 <otherwise>
145 <text>span</text>
146 </otherwise>
147 </choose>
148 </variable>
149 <attribute name="title">
150 <value-of select="rdfs:label[1]"/>
151 <text> (</text>
152 <value-of select="$curie"/>
153 <text>)</text>
154 </attribute>
155 <element name="html:{$wrappername}">
156 <attribute name="lang">
157 <value-of select="rdfs:label[1]/@xml:lang"/>
158 </attribute>
159 <attribute name="xml:lang">
160 <value-of select="rdfs:label[1]/@xml:lang"/>
161 </attribute>
162 <value-of select="rdfs:label[1]"/>
163 </element>
164 </for-each>
165 </when>
166 <otherwise>
167 <apply-templates/>
168 </otherwise>
169 </choose>
170 </when>
171 <otherwise>
172 <apply-templates/>
173 </otherwise>
174 </choose>
175 </copy>
176 </template>
177 <template match="/rdf:RDF//html:a/@href[starts-with(., '#footnote-')]">
178 <attribute name="href">
179 <text>#footnote-</text>
180 <value-of select="generate-id(ancestor::rdfs:comment//@id[string()=substring-after(current(), '#')])"/>
181 </attribute>
182 </template>
183 <template match="/rdf:RDF//html:*/@id[starts-with(., 'footnote-')]" priority="1">
184 <attribute name="id">
185 <text>footnote-</text>
186 <value-of select="generate-id()"/>
187 </attribute>
188 </template>
189 </transform>
This page took 0.068242 seconds and 5 git commands to generate.