Initial revision
[TestXSLT.git] / Distribution / More Examples / Safari Bookmarks / safaribookmarks2html.xslt
1 <?xml version='1.0' encoding='iso-8859-1'?>
2
3 <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
4
5 <xsl:output method='html' version='1.0' encoding='iso-8859-1' indent='no'/>
6
7 <!-- An XSLT style sheet to convert a Safari bookmarks list to HTML -->
8 <!-- You can find your Safari bookmarks file in your home directory under
9      Library / Safari / Bookmarks.plist -->
10      
11 <!-- Written by Marc Liyanage (http://www.entropy.ch) -->
12
13
14
15 <!-- Match toplevel element, emit basic HTML document structure -->
16
17 <xsl:template match="plist">
18
19 <html>
20
21         <head>
22         
23                 <title>Safari Bookmarks</title>
24         
25                 <style type="text/css">
26                         .category       
27                         {
28                                 border-color: #333333;
29                                 border-style: solid;
30                                 border-width: 1px;
31                                 margin: 10px 4px 4px 10px;
32                                 background-color: #cccccc;
33                         }
34                         .indent { margin-left: 10px; }
35                         .categorytitle  
36                         {
37                                 font-family: Georgia;
38                                 font-size: 16px;
39                                 font-weight: bold;
40                                 font-style: italic;
41                                 color: white;
42                                 background-color: #333333;
43                                 padding: 1px;
44                         }
45                         .link   
46                         {
47                                 font-family: Georgia;
48                                 font-size: 14px;
49                                 font-weight: normal;
50                                 margin: 2px 2px 2px 10px;
51                         }
52                         a { text-decoration: none; }
53                         a:hover { text-decoration: underline; }
54                 </style>
55         
56         </head>
57
58         <body>
59                 <!-- recursively create the body content -->
60                 <xsl:apply-templates/>
61         </body>
62
63 </html>
64
65 </xsl:template>
66
67
68
69
70
71 <!-- This generic template matches dict entries which act as containers for other items -->
72 <xsl:template match="dict">
73
74         <xsl:variable name="title" select="string[preceding-sibling::key[text() = 'Title']]"/>
75
76         <div class="category">
77                 <xsl:if test="$title"><div class="categorytitle"><xsl:value-of select="$title"/></div></xsl:if>
78                 <xsl:apply-templates select="array"/>
79         </div>
80         
81 </xsl:template>
82
83
84 <!-- This more specific template matches dict entries which contain a particular link. Because
85      it is more specific it will have precedence over the one above. -->
86 <xsl:template match="dict[key[text() = 'URIDictionary']]">
87
88                 <div class="link"><a href="{string[preceding-sibling::key[text() = 'URLString']]}"><xsl:value-of select="dict[preceding-sibling::key[text() = 'URIDictionary']]/string[preceding-sibling::key[text() = 'title']]"/></a></div>
89
90 </xsl:template>
91
92
93
94 </xsl:stylesheet>