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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tc="http://periapsis.org/tellico/"
exclude-result-prefixes="tc"
version="1.0">
<!--
===================================================================
Tellico XSLT file - Entry template for videos
Copyright (C) 2003-2006 Robby Stephenson - [email protected]
Known Issues:
o If there is more an one image, there's a lot of white space under
the top tables.
This XSLT stylesheet is designed to be used with the 'Tellico'
application, which can be found at http://www.periapsis.org/tellico/
===================================================================
-->
<!-- import common templates -->
<!-- location depends on being installed correctly -->
<xsl:import href="../tellico-common.xsl"/>
<xsl:output method="html"
indent="yes"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
encoding="utf-8"/>
<xsl:param name="datadir"/> <!-- dir where Tellico data are located -->
<xsl:param name="imgdir"/> <!-- dir where field images are located -->
<xsl:param name="font"/> <!-- font family -->
<xsl:param name="fontsize"/> <!-- font size -->
<xsl:param name="fgcolor"/> <!-- foreground color -->
<xsl:param name="bgcolor"/> <!-- background color -->
<xsl:param name="color1"/> <!-- highlighted text color -->
<xsl:param name="color2"/> <!-- highlighted background color -->
<xsl:param name="collection-file"/> <!-- might have a link to parent collection -->
<xsl:key name="fieldsByName" match="tc:field" use="@name"/>
<xsl:key name="fieldsByCat" match="tc:field" use="@category"/>
<xsl:key name="imagesById" match="tc:image" use="@id"/>
<xsl:variable name="endl">
<xsl:text>
</xsl:text>
</xsl:variable>
<!-- all the categories -->
<xsl:variable name="categories" select="/tc:tellico/tc:collection/tc:fields/tc:field[generate-id(.)=generate-id(key('fieldsByCat',@category)[1])]/@category"/>
<!-- all the tracks -->
<xsl:variable name="tracks" select="/tc:tellico/tc:collection/tc:fields/tc:field[starts-with(@name,'track')]"/>
<xsl:template match="/">
<xsl:apply-templates select="tc:tellico"/>
</xsl:template>
<!-- The default layout is pretty boring, but catches every field value in
the entry. The title is in the top H1 element. -->
<xsl:template match="tc:tellico">
<!-- This stylesheet is designed for Tellico document syntax version 10 -->
<xsl:call-template name="syntax-version">
<xsl:with-param name="this-version" select="'10'"/>
<xsl:with-param name="data-version" select="@syntaxVersion"/>
</xsl:call-template>
<html>
<head>
<style type="text/css">
body {
margin: .2em 1%;
padding: 0;
font-family: "<xsl:value-of select="$font"/>", Arial, Helvetica, sans-serif;
font-size: <xsl:value-of select="$fontsize"/>pt;
background-color: <xsl:value-of select="$bgcolor"/>;
color: <xsl:value-of select="$fgcolor"/>;
line-height: 1.6;
}
#banner {
padding-bottom: .2em;
margin-bottom: .2em;
}
img#logo {
padding-top: .3em; /* match h1 */
}
h1 {
color: <xsl:value-of select="$color1"/>;
background-color: <xsl:value-of select="$color2"/>;
background-image: url(<xsl:value-of select="concat($imgdir, 'gradient_header.png')"/>);
background-repeat: repeat-x;
font-size: 1.8em;
text-align: left;
padding: .1em .5em;
margin: 0;
font-weight: bold;
}
span.title {
font-style: italic
}
img {
padding-right: 6px;
padding-bottom: 6px;
border: 0px;
}
table.category {
margin-bottom: 6px;
float: left;
}
tr.category {
font-weight: bold;
font-size: 1.2em;
color: #fff;
background-color: #666;
text-align: center;
}
th {
font-weight: bold;
text-align: left;
color: black;
background: #ccc;
}
td.fieldValue {
color: black;
background: #ddd;
}
th, td.fieldValue {
padding: .1em .3em;
}
p {
margin-top: 0px;
text-align: justify;
}
img {
border: 0px solid;
}
<!-- since text is our own color, links have to be, too -->
a {
color: #006;
}
p.navigation {
font-weight: bold;
text-align: center;
clear: both;
}
</style>
<title>
<xsl:value-of select="tc:collection/tc:entry[1]//tc:title[1]"/>
<xsl:text> – </xsl:text>
<xsl:value-of select="tc:collection/@title"/>
</title>
</head>
<body>
<xsl:apply-templates select="tc:collection[1]"/>
<xsl:if test="$collection-file">
<p class="navigation">
<a href="{$collection-file}"><< <xsl:value-of select="tc:collection/@title"/></a>
</p>
</xsl:if>
</body>
</html>
</xsl:template>
<!-- type 3 is video collections -->
<!-- warn user that this template is meant for videos only. -->
<xsl:template match="tc:collection[@type!=4]">
<h1><i18n>This template is meant for music collections only.</i18n></h1>
</xsl:template>
<xsl:template match="tc:collection[@type=4]">
<xsl:apply-templates select="tc:entry[1]"/>
</xsl:template>
<xsl:template match="tc:entry">
<xsl:variable name="entry" select="."/>
<xsl:variable name="titleCat" select="key('fieldsByName','title')/@category"/>
<!-- the top table has images in the left cell and main fields in the right.
2 images can be on the left -->
<table width="100%" class="category">
<tr>
<!-- now, show all the images in the entry, type 10 -->
<xsl:variable name="images" select="../tc:fields/tc:field[@type=10]"/>
<!-- only insert cell if at least one image -->
<xsl:if test="$entry/*[local-name(.) = $images[1]/@name]">
<td valign="top" rowspan="2">
<xsl:for-each select="$images">
<!-- images will never be multiple, so no need to check for that -->
<!-- find the value of the image field in the entry -->
<xsl:variable name="image" select="$entry/*[local-name(.) = current()/@name]"/>
<!-- check if the value is not empty -->
<xsl:if test="$image">
<a>
<xsl:attribute name="href">
<xsl:choose>
<!-- Amazon license requires the image to be linked to the amazon website -->
<xsl:when test="$entry/tc:amazon">
<xsl:value-of select="$entry/tc:amazon"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="image-link">
<xsl:with-param name="image" select="key('imagesById', $image)"/>
<xsl:with-param name="dir" select="$imgdir"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<img alt="">
<xsl:attribute name="src">
<xsl:call-template name="image-link">
<xsl:with-param name="image" select="key('imagesById', $image)"/>
<xsl:with-param name="dir" select="$imgdir"/>
</xsl:call-template>
</xsl:attribute>
<!-- limit to maximum width of 150 and height of 200 -->
<xsl:call-template name="image-size">
<xsl:with-param name="limit-width" select="150"/>
<xsl:with-param name="limit-height" select="200"/>
<xsl:with-param name="image" select="key('imagesById', $image)"/>
</xsl:call-template>
</img>
</a>
</xsl:if>
</xsl:for-each>
</td>
</xsl:if>
<!-- want all the width we can get -->
<td valign="top">
<!-- now a nested table with the general fields -->
<div id="banner">
<h1>
<xsl:choose>
<xsl:when test="count(.//tc:artist) = 1">
<xsl:value-of select=".//tc:artist[1]"/>
</xsl:when>
<xsl:otherwise>
<i18n>(Various)</i18n>
</xsl:otherwise>
</xsl:choose>
<xsl:text> – </xsl:text>
<span class="title">
<xsl:value-of select=".//tc:title[1]"/>
</span>
<!-- Tellico 0.8 had multiple years in the default video collection -->
<xsl:if test=".//tc:year">
<span class="year">
<xsl:text> (</xsl:text>
<xsl:value-of select=".//tc:year[1]"/>
<xsl:text>)</xsl:text>
</span>
</xsl:if>
</h1>
</div>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%">
<xsl:for-each select="key('fieldsByCat', $titleCat)">
<xsl:if test="@name != 'title'">
<tr>
<th>
<xsl:value-of select="@title"/>
</th>
<td class="fieldValue" width="100%">
<xsl:call-template name="simple-field-value">
<xsl:with-param name="entry" select="$entry"/>
<xsl:with-param name="field" select="@name"/>
</xsl:call-template>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</td>
</tr>
</table>
<!-- doo all the track fields first -->
<xsl:variable name="artist" select="tc:artists/tc:artist[1]"/>
<xsl:for-each select="$tracks">
<xsl:variable name="fieldName" select="current()/@name"/>
<xsl:call-template name="trackField">
<xsl:with-param name="values" select="$entry/*[local-name()=concat($fieldName,'s')]"/>
<xsl:with-param name="name" select="$fieldName"/>
<xsl:with-param name="artist" select="$artist"/>
</xsl:call-template>
<!-- special case for tracks, since they're usually long tables.
clear after every 2nd table -->
<xsl:if test="position() mod 2 = 0">
<br style="clear:left" />
</xsl:if>
</xsl:for-each>
<!-- now for every thing else -->
<!-- write categories other than general and images -->
<xsl:for-each select="$categories[. != $titleCat and
not(starts-with(key('fieldsByCat',.)[1]/@name,'track')) and
key('fieldsByCat',.)[1]/@type != 10]">
<xsl:variable name="category" select="."/>
<xsl:variable name="fields" select="key('fieldsByCat', $category)"/>
<xsl:variable name="first-type" select="$fields[1]/@type"/>
<xsl:variable name="n" select="count($entry//*[key('fieldsByName',local-name(.))/@category=$category])"/>
<!-- only output if there are field values in this category -->
<xsl:if test="$n > 0">
<table width="50%" class="category">
<tr class="category">
<td colspan="2">
<xsl:attribute name="colspan">
<xsl:if test="$first-type = 2">1</xsl:if>
<xsl:if test="not($first-type = 2)">2</xsl:if>
</xsl:attribute>
<xsl:value-of select="."/>
</td>
</tr>
<xsl:for-each select="$fields">
<xsl:if test="$entry//*[local-name(.)=current()/@name]">
<tr>
<xsl:choose>
<!-- paragraphs -->
<xsl:when test="@type = 2">
<td class="fieldValue" width="100%">
<p>
<xsl:value-of select="$entry/*[local-name(.)=current()/@name]" disable-output-escaping="yes"/>
</p>
</td>
</xsl:when>
<!-- tables are field type 8 -->
<!-- ok to put category name inside div instead of table here -->
<xsl:when test="@type = 8">
<td>
<!-- look at number of columns -->
<xsl:choose>
<xsl:when test="tc:prop[@name = 'columns'] > 1">
<table>
<xsl:if test="tc:prop[@name = 'column1']">
<thead>
<tr>
<xsl:call-template name="columnTitle">
<xsl:with-param name="index" select="1"/>
<xsl:with-param name="max" select="tc:prop[@name = 'columns']"/>
<xsl:with-param name="elem" select="'th'"/>
<xsl:with-param name="field" select="."/>
</xsl:call-template>
</tr>
</thead>
</xsl:if>
<tbody>
<xsl:for-each select="$entry//*[local-name(.) = current()/@name]">
<tr>
<xsl:for-each select="tc:column">
<td>
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:for-each select="$entry//*[local-name(.) = current()/@name]">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ul>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:when>
<!-- everything else -->
<xsl:otherwise>
<th>
<xsl:value-of select="@title"/>
</th>
<td class="fieldValue" width="100%">
<xsl:call-template name="simple-field-value">
<xsl:with-param name="entry" select="$entry"/>
<xsl:with-param name="field" select="@name"/>
</xsl:call-template>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="trackField">
<xsl:param name="values"/>
<xsl:param name="name"/>
<xsl:param name="artist"/>
<xsl:variable name="field" select="key('fieldsByName', $name)"/>
<table width="50%" class="category">
<xsl:variable name="cols" select="count($values/*[1]/tc:column)"/>
<tr class="category">
<td colspan="{$cols}">
<xsl:value-of select="$field/@category"/>
</td>
</tr>
<xsl:if test="$field/tc:prop[@name = 'column1']">
<tr>
<th colspan="2" style="text-align:center">
<xsl:value-of select="$field/tc:prop[@name = 'column1']"/>
<xsl:if test="not($values/*[1]/tc:column[2] = $artist)">
<xsl:text> / </xsl:text>
<em><xsl:value-of select="$field/tc:prop[@name = 'column2']"/></em>
</xsl:if>
</th>
<th style="text-align:center">
<xsl:value-of select="$field/tc:prop[@name = 'column3']"/>
</th>
<xsl:call-template name="columnTitle">
<xsl:with-param name="index" select="4"/>
<xsl:with-param name="max" select="$cols"/>
<xsl:with-param name="elem" select="'th'"/>
<xsl:with-param name="field" select="$field"/>
</xsl:call-template>
</tr>
</xsl:if>
<xsl:for-each select="$values/*">
<tr>
<th style="text-align:center">
<xsl:value-of select="format-number(position(), '00')"/>
</th>
<xsl:choose>
<!-- a three column table could have an empty third column -->
<xsl:when test="$cols > 1">
<!-- if it has three columns, assume first is title,
second is artist and third is track length. -->
<td class="fieldValue">
<xsl:if test="string-length(tc:column[1])">
<xsl:value-of select="tc:column[1]"/>
</xsl:if>
<xsl:if test="string-length(tc:column[2]) and not(tc:column[2] = $artist)">
<xsl:text> / </xsl:text>
<em><xsl:value-of select="tc:column[2]"/></em>
</xsl:if>
</td>
<td class="fieldValue" style="text-align: right; padding-right: 10px">
<em><xsl:value-of select="tc:column[3]"/></em>
</td>
</xsl:when>
<xsl:otherwise>
<td class="fieldValue">
<xsl:value-of select="."/>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
<!-- if it has multiple columns,
and the final one has a ':', add the time together -->
<!-- it should still work if the first row itself doesn't contain a ':' -->
<xsl:if test="$cols > 1 and
count($values/*[contains(tc:column[number($cols)], ':')])">
<tr>
<th colspan="2" style="text-align: right; padding-right: 10px;">
<strong><i18n>Total:</i18n> </strong>
</th>
<td class="fieldValue" style="text-align: right; padding-right: 10px">
<em>
<xsl:call-template name="sumTime">
<xsl:with-param name="nodes" select="$values//tc:column[number($cols)]"/>
</xsl:call-template>
</em>
</td>
</tr>
</xsl:if>
</table>
</xsl:template>
</xsl:stylesheet>
|