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