emblem.xsl 5.38 KB
Newer Older
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
<xsl:transform version="2.0"
               exclude-result-prefixes="#all"
               xmlns:dct="http://purl.org/dc/terms/"
               xmlns:foaf="http://xmlns.com/foaf/0.1/"
               xmlns:owl="http://www.w3.org/2002/07/owl#"
               xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
               xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" encoding="utf-8"/>

  <xsl:template match="rdf:RDF">
    <html>
      <head>
        <title><xsl:value-of select="rdf:Description/dct:title[1]"/></title>
        <style type="text/css">
          body { max-width: 60em; margin: 0 auto; font-family: "Open Sans", sans-serif; }
          table, tr, th, td { border-collapse: collapse; }
          th { text-align: left; vertical-align: top; }
          th, td { padding: 0.25em 0.5em; }
        </style>
        <link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" />
        <xsl:for-each select="rdf:Description/dct:*">
          <xsl:if test="normalize-space()">
            <meta name="DCTERMS.{local-name()}" content="{normalize-space()}"/>
          </xsl:if>
          <xsl:for-each select="owl:sameAs | foaf:page | foaf:homepage">
            <link rel="DCT.{local-name(..)}" href="{@rdf:resource}"/>
          </xsl:for-each>
        </xsl:for-each>
      </head>
      <body>
        <xsl:apply-templates select="rdf:Description"/>
        <h2>Classes</h2>
        <xsl:apply-templates select="rdfs:Class"/>
        <h2>Properties</h2>
        <xsl:apply-templates select="rdfs:Property"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="rdf:Description">
    <h1><xsl:value-of select="dct:title[1]"/></h1>
    <ul>
      <xsl:for-each select="dct:creator/foaf:Person">
        <xsl:sort select="foaf:name"/>
        <li>
          <xsl:value-of select="foaf:name"/>
          <xsl:if test="foaf:mbox">
            <xsl:value-of select="concat(' &lt;', substring-after(foaf:mbox/@rdf:resource, 'mailto:'), '&gt;')"/>
          </xsl:if>
        </li>
      </xsl:for-each>
    </ul>
David Maus's avatar
David Maus committed
55
56
57
    <div>
      <xsl:value-of select="dct:description[1]"/>
    </div>
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
    <h2>See also</h2>
    <ul>
      <xsl:for-each select="dct:relation">
        <li>
          <a href="{foaf:homepage/@rdf:resource}" target="_blank">
            <xsl:value-of select="dct:title[1]"/>
          </a>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>

  <xsl:template match="rdfs:Class">
    <h3 id="{substring-after(@rdf:about, '#')}"><xsl:value-of select="rdfs:label[not(@xml:lang) or @xml:lang = 'en']"/></h3>
    <table>
      <tbody>
        <xsl:call-template name="common-properties"/>
        <xsl:if test="../rdfs:Class/rdfs:subClassOf[@rdf:resource = current()/@rdf:about]">
          <tr>
            <th>Subclasses</th>
            <td>
              <xsl:for-each select="../rdfs:Class[rdfs:subClassOf[@rdf:resource = current()/@rdf:about]]">
                <xsl:if test="position() &gt; 1">
                  <xsl:text>, </xsl:text>
                </xsl:if>
                <xsl:call-template name="uri-to-link">
                  <xsl:with-param name="target" select="@rdf:about"/>
                </xsl:call-template>
              </xsl:for-each>
            </td>
          </tr>
        </xsl:if>
        <xsl:if test="../rdfs:Property/rdfs:domain[@rdf:resource = current()/@rdf:about]">
          <tr>
            <th>Properties</th>
            <td>
              <xsl:for-each select="../rdfs:Property[rdfs:domain[@rdf:resource = current()/@rdf:about]]">
                <xsl:if test="position() &gt; 1">
                  <xsl:text>, </xsl:text>
                </xsl:if>
                <xsl:call-template name="uri-to-link">
                  <xsl:with-param name="target" select="@rdf:about"/>
                </xsl:call-template>
              </xsl:for-each>
            </td>
          </tr>
        </xsl:if>
      </tbody>
    </table>
  </xsl:template>

  <xsl:template match="rdfs:Property">
    <h3 id="{substring-after(@rdf:about, '#')}"><xsl:value-of select="rdfs:label[not(@xml:lang) or @xml:lang = 'en']"/></h3>
    <table>
      <tbody>
        <xsl:call-template name="common-properties"/>
      </tbody>
    </table>
  </xsl:template>

  <xsl:template name="uri-to-link">
    <xsl:param name="target" select="@rdf:resource"/>
    <xsl:choose>
      <xsl:when test="starts-with($target, 'http://uri.hab.de/ontology/emblem#')">
        <a href="#{substring-after($target, '#')}">
          <xsl:value-of select="substring-after($target, '#')"/>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <a href="{$target}" target="_blank">
          <xsl:value-of select="$target"/>
        </a>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="common-properties">
    <tr>
      <th>URI</th><td><xsl:value-of select="@rdf:about"/></td>
    </tr>
    <xsl:for-each select="rdfs:*[not(@xml:lang) or @xml:lang = 'en'][not(local-name() = 'label')]">
      <tr>
        <th><xsl:value-of select="local-name()"/></th>
        <td>
          <xsl:choose>
            <xsl:when test="@rdf:resource">
              <xsl:value-of select="@rdf:resource"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="normalize-space()"/>
            </xsl:otherwise>
          </xsl:choose>
        </td>
      </tr>
    </xsl:for-each>
  </xsl:template>

</xsl:transform>