grokCV.xsl
5.8 KB
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
<xsl:stylesheet
xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:h ="http://www.w3.org/1999/xhtml"
xmlns:s ="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf ="http://xmlns.com/foaf/0.1/"
xmlns:k ="http://opencyc.sourceforge.net/daml/cyc.daml#"
xmlns:card ="http://www.w3.org/2006/03/hcard#"
xmlns:con ="http://www.w3.org/2000/10/swap/pim/contact#"
xmlns:usps ="http://www.w3.org/2000/10/swap/pim/usps#"
xmlns:whois="http://www.kanzaki.com/ns/whois#"
xmlns:cv ="http://www.w3.org/2000/10/swap/pim/cv@@#"
xmlns:r ="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<div xmlns="http://www.w3.org/1999/xhtml">
<h2>Issue</h2>
<ul>
<li>hash-vs-slash in foaf</li>
</ul>
<address>$Id: grokCV.xsl,v 1.3 2006/07/12 21:44:09 connolly Exp $</address>
</div>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="h:html">
<r:RDF>
<foaf:Document r:about="">
<xsl:apply-templates />
</foaf:Document>
</r:RDF>
</xsl:template>
<xsl:template match="h:body">
<xsl:for-each select='h:h1/*[@class="docClassName"]'>
<r:type r:parseType="Resource">
<s:label><xsl:value-of select='normalize-space(.)'/></s:label>
</r:type>
</xsl:for-each>
<foaf:primaryTopic>
<foaf:Person><!-- sometimes an org? -->
<xsl:apply-templates mode="vcard-mode" select="."/>
<xsl:for-each select='h:body/*[@class="affiliation"]'>
<xsl:variable name='positionName'
select='normalize-space(*[@class="position"])'/>
<xsl:variable name='orgName'
select='normalize-space(*[@class="org"])'/>
<xsl:variable name='orgHome'
select='*[@class="org"]/h:a[@rel="aff"]/@href'/>
<!-- hmm... use a cyc:PartProperty in stead? -->
<!-- this construct takes us out of OWL DL -->
<r:type>
<s:Class>
<s:label><xsl:value-of select='$positionName'/></s:label>
<cv:org r:parseType="Resource">
<s:label><xsl:value-of select='$orgName'/></s:label>
<foaf:homepage r:resource='{$orgHome}'/>
</cv:org>
</s:Class>
</r:type>
</xsl:for-each>
</foaf:Person>
</foaf:primaryTopic>
</xsl:template>
<xsl:template mode="vcard-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" vcard ")]'>
<xsl:message>vcard mode: <xsl:value-of select="name()" /></xsl:message>
<k:subAbstrac r:parseType="Resource">
<xsl:apply-templates select="." mode="vcard-prop-mode" />
</k:subAbstrac>
</xsl:template>
<xsl:template mode="vcard-prop-mode"
match='h:object[
contains(concat(" ", normalize-space(@class), " "),
" include ")
and substring(@data, 1, 1) = "#"]'>
<xsl:message>vcard-prop-mode: include: <xsl:value-of select="name()" /></xsl:message>
<xsl:variable name="target" select="substring(@data, 2)" />
<xsl:apply-templates select="//*[@id = $target]" mode="vcard-prop-mode" />
</xsl:template>
<xsl:template mode="vcard-prop-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" fn ")]'>
<xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>
<foaf:name>
<xsl:value-of select="." />
</foaf:name>
</xsl:template>
<xsl:template mode="vcard-prop-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" title ")]'>
<xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>
<card:title>
<!-- textprop... @@abbr title, img alt, etc. -->
<xsl:value-of select="." />
</card:title>
</xsl:template>
<xsl:template mode="vcard-prop-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" url ")]'>
<xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>
<xsl:variable name="ref">
<xsl:choose>
<xsl:when test='name() = "a" and @href'>
<xsl:value-of select='@href' />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='.' />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- absolutize? -->
<card:url r:resource="{$ref}" />
</xsl:template>
<xsl:template mode="vcard-prop-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" adr ")]'>
<xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>
<con:office>
<usps:MailingLocation>
<xsl:apply-templates select="." mode="adr-mode" />
</usps:MailingLocation>
</con:office>
</xsl:template>
<xsl:template mode="adr-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" street-address ")]'>
<usps:deliveryAddress>
<xsl:value-of select="normalize-space(.)" />
</usps:deliveryAddress>
</xsl:template>
<xsl:template mode="adr-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" locality ")]'>
<usps:cityName>
<xsl:value-of select="normalize-space(.)" />
</usps:cityName>
</xsl:template>
<xsl:template mode="adr-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" region ")]'>
<usps:stateAbbr>
<xsl:value-of select="normalize-space(.)" />
</usps:stateAbbr>
</xsl:template>
<xsl:template mode="adr-mode"
match='*[
contains(concat(" ", normalize-space(@class), " "),
" postal-code ")]'>
<usps:zipCode>
<xsl:value-of select="normalize-space(.)" />
</usps:zipCode>
</xsl:template>
<xsl:template name="findByClass"> <!-- @@dead code -->
<xsl:param name="class" />
<xsl:for-each select='
descendant-or-self::*[
contains(concat(" ", normalize-space(@class), " "),
concat(" ", $class, " "))]'>
<xsl:copy />
</xsl:for-each>
</xsl:template>
<!-- don't pass text thru -->
<xsl:template match="text()" />
<xsl:template match="text()" mode="vcard-mode"/>
<xsl:template match="text()" mode="vcard-prop-mode" />
<xsl:template match="text()" mode="adr-mode" />
</xsl:stylesheet>