Annotation of 2001/palmagent/asHCard.xsl, revision 1.7
1.1 connolly 1: <xsl:transform
2: xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3: version="1.0"
4: xmlns:h="http://www.w3.org/1999/xhtml"
5: xmlns:d='http://dev.w3.org/2001/palmagent/danger#'
6: xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
7: >
8:
1.4 connolly 9: <blockquote
10: xmlns="http://www.w3.org/1999/xhtml">
11: <h1>asHCard.xsl -- transform Danger contacts in RDF to hCard</h1>
12:
13: <p>See also: <a
14: href="http://developers.technorati.com/wiki/hCard">hCard</a>, <a
15: href="http://www.advogato.org/person/connolly/diary.html?start=26">Using
16: hCard, XSLT, and RDF to sync the family cellphones</a>, advogato
17: diary entry 26 Jun 2005</p>
18:
19: <pre>
20: $Log: asHCard.xsl,v $
1.7 ! connolly 21: Revision 1.6 2005年06月26日 22:38:44 connolly
! 22: - labels on url, adr, email
! 23:
1.6 connolly 24: Revision 1.5 2005年06月26日 22:03:00 connolly
25: - use real nickname property rather than additional-name
26: (works with apple addressbook)
27: - fix UID code, partly
28:
1.5 connolly 29: Revision 1.4 2005年06月26日 21:44:41 connolly
30: cited some sources; moved log, Id from XML comments to XHTML
31:
1.4 connolly 32: Revision 1.3 2005年06月26日 21:36:52 connolly
33: - handle email addresses (but not labels)
34: - move category to end of entry
35:
36: Revision 1.2 2005年06月26日 21:27:00 connolly
37: - handle telephones, including converting labels to types
38: - handle addresses
39: - handle notes
40: - handle nickname-only items
41: - convert urls to XHTML (though not to vCard)
42: - handle categories... one, anyway
43:
44: Revision 1.1 2005年06月26日 20:46:27 connolly
45: handles name (first, middle, last) and company
46: </pre>
47:
48: <address>
49: <a href="http://www.w3.org/People/Connolly/">Dan Connolly</a>
50: <br />
1.7 ! connolly 51: <small>$Id: asHCard.xsl,v 1.6 2005年06月26日 22:38:44 connolly Exp $</small>
1.4 connolly 52: </address>
53: </blockquote>
1.1 connolly 54:
55: <xsl:output method="xml" indent="yes" />
56:
57: <xsl:param name="Category" select='"Medical"' />
58: <xsl:param name="Base" select='"http://address.sidekick.dngr.com/show?contact_id="' />
59:
60:
61: <xsl:template match="/">
62: <html
63: xmlns="http://www.w3.org/1999/xhtml">
1.7 ! connolly 64: <head>
! 65: <title>
! 66: <xsl:text>Contacts</xsl:text>
! 67: <xsl:if test="$Category">
! 68: <xsl:text>: </xsl:text>
! 69: <xsl:value-of select="$Category" />
! 70: </xsl:if>
! 71: </title>
1.1 connolly 72: <!-- profile? -->
73: </head>
74: <body>
75: <h1>Contacts</h1>
76: <p>@@pointer to source? last update?</p>
1.4 connolly 77: <address>converted from <em>some</em> contact.rdf using asHCard.xsl from <a href="http://dev.w3.org/cvsweb/2001/palmagent/">palmagent</a></address>
1.1 connolly 78:
79: <!-- for each category... -->
80: <div>
1.7 ! connolly 81: <xsl:if test="$Category">
! 82: <h2><xsl:value-of select="$Category" /></h2>
! 83: </xsl:if>
1.1 connolly 84: <ul>
85: <xsl:apply-templates />
86: </ul>
87: </div>
88: </body>
89: </html>
90: </xsl:template>
91:
1.7 ! connolly 92: <xsl:template match="d:contact[not($Category) or d:category=$Category]">
1.1 connolly 93: <li class="vcard"
94: xmlns="http://www.w3.org/1999/xhtml"
1.5 connolly 95: id='{@rdf:ID}'> <!-- umm... uids are global, no? @@-->
1.2 connolly 96:
97: <!-- @@ last-modified -->
98:
99: <xsl:choose>
100: <xsl:when test="d:last_name or d:first_name">
101: <span class="n">
102: <span class="Family-Name"><xsl:value-of select="d:last_name" /></span>
103: <xsl:text>, </xsl:text>
104: <span class="Given-Name"><xsl:value-of select="d:first_name" /></span>
105: <xsl:if test="d:middle_name">
106: <xsl:text> </xsl:text>
107: <span class="Additional-Name"><xsl:value-of select="d:middle_name" /></span>
108: </xsl:if>
109: <xsl:if test="d:nick_name">
110: <xsl:text> </xsl:text>
1.5 connolly 111: <em class="nickname"><xsl:value-of select="d:nick_name" /></em>
1.2 connolly 112: </xsl:if>
113: </span>
114: </xsl:when>
115:
116: <xsl:when test="d:nick_name">
1.5 connolly 117: <em class="n nickname"><xsl:value-of select="d:nick_name" /></em>
1.2 connolly 118: </xsl:when>
119: </xsl:choose>
120:
1.1 connolly 121: <xsl:if test="d:company">
122: <div class="org"><xsl:value-of select="d:company" /></div>
123: </xsl:if>
1.2 connolly 124:
125: <xsl:if test="d:urls/d:urls_item">
126: <ul>
127: <xsl:for-each select="d:urls/d:urls_item">
1.6 connolly 128: <li><a class="url" href="{d:address}"><xsl:value-of select="d:label" /></a></li>
129: <!-- hmm... label gets lost in conversion to vCard -->
1.2 connolly 130: </xsl:for-each>
131: </ul>
132: </xsl:if>
133:
134: <xsl:if test="d:addresses/d:addresses_item/*">
135: <ul>
136: <xsl:for-each select="d:addresses/d:addresses_item">
1.6 connolly 137: <!--
138: The TYPE parameter values can include "dom" to
139: indicate a domestic delivery address; "intl" to indicate an
140: international delivery address; "postal" to indicate a postal
141: delivery address; "parcel" to indicate a parcel delivery address;
142: "home" to indicate a delivery address for a residence; "work" to
143: indicate delivery address for a place of work; and "pref" to indicate
144: the preferred delivery address when more than one address is
145: specified. These type parameter values can be specified as a
146: parameter list (i.e., "TYPE=dom;TYPE=postal") or as a value list
147: (i.e., "TYPE=dom,postal"). This type is based on semantics of the
148: X.520 geographical and postal addressing attributes. The default is
149: "TYPE=intl,postal,parcel,work".
150: -->
151:
152: <!-- darn... xhtml2vcard.xsl (Version 0.4.7 2005年06月22日)
153: doesn't seem to grok ADR types -->
154: <xsl:variable name="typ">
155: <xsl:choose>
156: <xsl:when test='d:label="Home"'>
157: <xsl:text>intl postal parcel dom</xsl:text>
158: </xsl:when>
159:
160: <xsl:when test='d:label="Work"'>
161: <xsl:text>intl postal parcel work</xsl:text>
162: </xsl:when>
163:
1.7 ! connolly 164: <xsl:when test='d:label="Unlabeled" or string(d:label)=""'>
1.6 connolly 165: <xsl:text>intl postal parcel work</xsl:text>
166: </xsl:when>
167:
168: <xsl:otherwise>
1.7 ! connolly 169: <xsl:message>unknown address label: [<xsl:value-of select="d:label" />]</xsl:message>
1.6 connolly 170: </xsl:otherwise>
171: </xsl:choose>
172: </xsl:variable>
173:
174: <li class="adr {$typ}">
1.2 connolly 175: <div class="street-address"><xsl:value-of select="d:street" /></div>
176: <div>
177: <span class="locality"><xsl:value-of select="d:city" /></span>
178: <xsl:text>, </xsl:text>
179: <span class="region"><xsl:value-of select="d:state" /></span>
180: <xsl:text> </xsl:text>
181: <span class="postal-code"><xsl:value-of select="d:zip" /></span>
182: </div>
183: </li>
184: </xsl:for-each>
185: </ul>
186: </xsl:if>
187:
1.3 connolly 188: <xsl:if test="d:email_addresses/d:email_addresses_item">
189: <ul>
190: <xsl:for-each select="d:email_addresses/d:email_addresses_item">
191: <li>
192: <xsl:value-of select="d:label" />
193: <xsl:text>: </xsl:text>
1.6 connolly 194: <!-- xhtml2vcard seems to only grok email address types
195: internet and pref :( -->
196: <a class="email {d:label}" href="mailto:{d:address}">
1.3 connolly 197: <xsl:value-of select="d:address" />
198: </a>
199: </li>
200: </xsl:for-each>
201: </ul>
202: </xsl:if>
203:
1.2 connolly 204: <xsl:for-each select="d:phone_numbers/d:phone_numbers_item">
205: <xsl:variable name="num" select="d:number" />
206:
207: <!--
208:
209: The TYPE parameter values can include:
210: "home" to indicate a telephone number associated with a residence,
211: "msg" to indicate the telephone number has voice messaging support,
212: "work" to indicate a telephone number associated with a place of
213: work, "pref" to indicate a preferred-use telephone number, "voice" to
214: indicate a voice telephone number, "fax" to indicate a facsimile
215: telephone number, "cell" to indicate a cellular telephone number,
216: "video" to indicate a video conferencing telephone number, "pager" to
217: indicate a paging device telephone number, "bbs" to indicate a
218: bulletin board system telephone number, "modem" to indicate a MODEM
219: connected telephone number, "car" to indicate a car-phone telephone
220: number, "isdn" to indicate an ISDN service telephone number, "pcs" to
221: indicate a personal communication services telephone number. The
222: default type is "voice".
223:
224: http://www.ietf.org/rfc/rfc2426.txt
225: -->
226: <xsl:variable name="typ">
227: <xsl:choose>
228: <xsl:when test='d:label = "Home"'>
229: <xsl:text>home msg</xsl:text>
230: </xsl:when>
231:
232: <xsl:when test='d:label = "Work"'>
233: <xsl:text>work msg</xsl:text>
234: </xsl:when>
235:
1.7 ! connolly 236: <xsl:when test='d:label = "Fax"'>
! 237: <xsl:text>fax</xsl:text>
! 238: </xsl:when>
! 239:
! 240: <xsl:when test='d:label = "Personal"'>
! 241: <!-- hmm... how to preserve one-to-one-ness? -->
! 242: <xsl:text>voice</xsl:text>
! 243: </xsl:when>
! 244:
! 245: <xsl:when test='d:label = "Toll Free"'>
! 246: <xsl:text>work msg</xsl:text>
! 247: </xsl:when>
! 248:
1.2 connolly 249: <xsl:when test='d:label = "Mobile"'>
250: <xsl:text>cell msg</xsl:text>
251: </xsl:when>
252:
1.7 ! connolly 253: <xsl:when test='d:label = "Unlabeled" or string(d:label)=""'>
1.2 connolly 254: <xsl:text>voice</xsl:text>
255: </xsl:when>
256:
257: <xsl:otherwise>
1.7 ! connolly 258: <xsl:message>unknown phone number label: [<xsl:value-of select="d:label" />]</xsl:message>
1.2 connolly 259: </xsl:otherwise>
260: </xsl:choose>
261: </xsl:variable>
262:
263: <div class="tel">
264: <xsl:value-of select="d:label" />
265: <xsl:text>: </xsl:text>
266: <!-- tel: URI needs formatting -->
267: <a class="{$typ}" href="tel:{$num}">
268: <xsl:value-of select="$num" />
269: </a>
270: </div>
271: </xsl:for-each>
272:
273: <xsl:if test="d:notes">
274: <blockquote class="note"><xsl:value-of select="d:notes" /></blockquote>
275: </xsl:if>
276:
1.3 connolly 277: <xsl:if test="d:category">
278: <div><small class="categories">
279: <xsl:value-of select="d:category" />
280: </small></div>
281: </xsl:if>
1.1 connolly 282: </li>
283: </xsl:template>
284:
285: <!-- don't pass text thru -->
286: <xsl:template match="text()"></xsl:template>
287:
288: </xsl:transform>
Webmaster