-
Notifications
You must be signed in to change notification settings - Fork 8
/
owl2html.xsl
210 lines (202 loc) · 7.58 KB
/
owl2html.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<xsl:output method="html"/>
<xsl:variable name="title" select="/rdf:RDF/owl:Ontology/rdfs:label"/>
<xsl:variable name="about" select="/rdf:RDF/owl:Ontology/@rdf:about"/>
<xsl:template match="/rdf:RDF">
<html>
<head>
<title><xsl:value-of select="$title"/></title>
<style>
h4 { margin-bottom: 0.25em; }
body { font-family: sans-serif; }
.about { font-family: monospace; margin-left: 1em; }
.label { margin-left: 1em; font-style:italic; }
.comment { margin-left: 1em; }
.property { margin-left: 1em; }
</style>
</head>
<body>
<h1><xsl:value-of select="$title"/></h1>
<div class="about"><xsl:value-of select="$about"/></div>
<xsl:for-each select="/rdf:RDF/owl:Ontology/rdfs:comment">
<div class="comment"><xsl:value-of select="."/></div>
</xsl:for-each>
<div class="table-of-contents">
<h2>Table of Contents</h2>
<xsl:if test="/rdf:RDF/owl:Class">
<h3>Classes</h3>
<xsl:for-each select="/rdf:RDF/owl:Class">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="link"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="/rdf:RDF/owl:NamedIndividual">
<h3>Named Individuals</h3>
<xsl:for-each select="/rdf:RDF/owl:NamedIndividual">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="link"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="/rdf:RDF/owl:ObjectProperty">
<h3>Object Properties</h3>
<xsl:for-each select="/rdf:RDF/owl:ObjectProperty">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="link"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="/rdf:RDF/owl:DatatypeProperty">
<h3>Datatype Properties</h3>
<xsl:for-each select="/rdf:RDF/owl:DatatypeProperty">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="link"/>
</xsl:for-each>
</xsl:if>
</div>
<div class="contents">
<h2>Entity Definitions</h2>
<xsl:if test="/rdf:RDF/owl:Class">
<h3>Classes</h3>
<xsl:for-each select="/rdf:RDF/owl:Class">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="description"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="/rdf:RDF/owl:NamedIndividual">
<h3>Named Individuals</h3>
<xsl:for-each select="/rdf:RDF/owl:NamedIndividual">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="description"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="/rdf:RDF/owl:ObjectProperty">
<h3>Object Properties</h3>
<xsl:for-each select="/rdf:RDF/owl:ObjectProperty">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="description"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="/rdf:RDF/owl:DatatypeProperty">
<h3>Datatype Properties</h3>
<xsl:for-each select="/rdf:RDF/owl:DatatypeProperty">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="description"/>
</xsl:for-each>
</xsl:if>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="link">
<xsl:variable name="id">
<xsl:choose>
<xsl:when test="@rdf:about and contains(@rdf:about,$about)">
<xsl:value-of select="substring-after(@rdf:about,$about)"/>
</xsl:when>
<xsl:when test="@rdf:resource and contains(@rdf:resource,$about)">
<xsl:value-of select="substring-after(@rdf:resource,$about)"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$id != ''">
<a href="#{$id}"><xsl:value-of select="$id"/></a>
</xsl:when>
<xsl:when test="contains(@rdf:resource,'http://www.w3.org/2001/XMLSchema#')">
<a href="{@rdf:resource}">xsd:<xsl:value-of select="substring-after(@rdf:resource,'#')"/></a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@rdf:resource"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template name="description">
<xsl:variable name="id" select="substring-after(@rdf:about,$about)"/>
<div id="{$id}">
<h4><xsl:value-of select="$id"/></h4>
<xsl:if test="rdfs:label">
<div class="label"><xsl:value-of select="rdfs:label"/></div>
</xsl:if>
<xsl:for-each select="rdfs:comment">
<div class="comment"><xsl:value-of select="."/></div>
</xsl:for-each>
<div class="property">type:
<xsl:value-of select="substring-after(name(),'owl:')"/>
</div>
<xsl:if test="rdfs:subClassOf">
<div class="property">subclass of:
<xsl:for-each select="rdfs:subClassOf">
<xsl:call-template name="link"/>
</xsl:for-each>
</div>
</xsl:if>
<xsl:if test="//*[contains(rdfs:domain/@rdf:resource,$id)]|//*[contains(rdfs:range/@rdf:resource,$id)]">
<div class="property">used with:
<xsl:for-each select="//*[contains(rdfs:domain/@rdf:resource,$id)]|//*[contains(rdfs:range/@rdf:resource,$id)]">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="link"/>
</xsl:for-each>
</div>
</xsl:if>
<xsl:if test="//*[rdf:type/@rdf:resource=concat($about,$id)]">
<div class="property">instances:
<xsl:for-each select="//*[rdf:type/@rdf:resource=concat($about,$id)]">
<xsl:sort select="@rdf:about"/>
<xsl:call-template name="link"/>
</xsl:for-each>
</div>
</xsl:if>
<xsl:if test="rdf:type">
<div class="property">rdf:type:
<xsl:for-each select="rdf:type">
<xsl:call-template name="link"/>
</xsl:for-each>
</div>
</xsl:if>
<xsl:if test="rdfs:domain">
<div class="property">
domain:
<xsl:for-each select="rdfs:domain">
<xsl:call-template name="link"/>
</xsl:for-each>
</div>
</xsl:if>
<xsl:if test="rdfs:range">
<div class="property">
range:
<xsl:for-each select="rdfs:range">
<xsl:call-template name="link"/>
</xsl:for-each>
</div>
</xsl:if>
</div>
</xsl:template>
<xsl:template match="/index">
<html>
<head>
<title><xsl:value-of select="@title"/></title>
<style>
h1 { font-size: large; }
body { font-family: sans-serif; }
</style>
</head>
<body>
<h1><xsl:value-of select="@title"/></h1>
<ul>
<xsl:for-each select="page">
<xsl:variable name="page_id" select="@id"/>
<xsl:for-each select="document(concat($page_id,'.rdf'))">
<xsl:variable name="title" select="rdf:RDF/owl:Ontology/rdfs:label"/>
<li><a href="{$page_id}/"><xsl:value-of select="$title"/></a></li>
</xsl:for-each>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
</xsl:stylesheet>