aboutsummaryrefslogtreecommitdiffstats
path: root/xslt/uddf-export.xslt
blob: bf4735f38f7ee0f94cd7be3fe83bdb92a12af582 (plain) (blame)
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xt="http://www.jclark.com/xt"
                extension-element-prefixes="xt" version="1.0">
  <xsl:include href="commonTemplates.xsl"/>
  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" encoding="utf-8" indent="yes"/>
  <xsl:param name="units" select="units"/>

  <xsl:key name="gases" match="cylinder" use="concat(substring-before(@o2, '.'), '/', substring-before(@he, '.'))" />
  <xsl:key name="images" match="picture" use="concat(../../dive/@number|../dive/@number, ':', @filename, '@', @offset)" />
  <xsl:key name="divecomputer" match="divecomputer" use="@deviceid" />

  <!-- This needs to be set at this top level so that it is avialable in both the buddies and profiledata sections-->
  <xsl:variable name="buddies">
    <xsl:for-each select="//buddy">
      <xsl:call-template name="tokenize">
        <xsl:with-param name="string" select="." />
        <xsl:with-param name="delim" select="', '" />
      </xsl:call-template>
    </xsl:for-each>
  </xsl:variable>

  <xsl:variable name="eventmap">
    <!--entry key="safety stop (mandatory)"></entry-->
    <!--entry key="deco"></entry-->
    <entry key="ascent">ascent</entry><!--Not sure of definitions in our file. Ascent too fast??-->
    <entry key="violation">deco</entry><!--Assume this is missed deco-->
    <!--entry key="below floor">error</entry-->
    <entry key="divetime">rbt</entry>
    <!--entry key="maxdepth"></entry-->
    <!--entry key="OLF"></entry-->
    <!--entry key="PO2"></entry-->
    <!--entry key="airtime"></entry-->
    <entry key="ceiling">error</entry>
    <!--entry key="heading"></entry-->
    <entry key="surface">surface</entry>
    <!--entry key="bookmark"></entry-->
    <entry key="unknown">error</entry>
  </xsl:variable>


  <xsl:template match="/divelog/settings"/>
  <xsl:template match="/divelog/divesites"/>

  <xsl:template match="/divelog/dives">
    <uddf version="3.2.0"  xmlns="http://www.streit.cc/uddf/3.2/">
      <generator>
        <name>Subsurface Divelog</name>
        <manufacturer id="subsurface">
          <name>Subsurface Team</name>
          <contact>
            <homepage>http://subsurface-divelog.org/</homepage>
          </contact>
        </manufacturer>
        <version>
          <xsl:value-of select="/divelog/@version"/>
        </version>
        <xsl:if test="/divelog/generator/@date != ''">
          <datetime>
            <xsl:value-of select="concat(/divelog/generator/@date, 'T', /divelog/generator/@time)"/>
          </datetime>
        </xsl:if>
      </generator>
      <mediadata>
        <xsl:for-each select="//picture[generate-id() = generate-id(key('images', concat(../../dive/@number|../dive/@number, ':', @filename, '@', @offset))[1])]">
          <image id="{concat(../../dive/@number|../dive/@number, ':', @filename, '@', @offset)}">
            <objectname>
              <xsl:value-of select="@filename"/>
            </objectname>
          </image>
        </xsl:for-each>
      </mediadata>
      <diver>
        <owner id="owner">
          <personal>
            <firstname></firstname>
            <lastname></lastname>
          </personal>
          <equipment>
            <xsl:for-each select="//dive/divecomputer[generate-id() = generate-id(key('divecomputer', @deviceid)[1])]">
              <divecomputer id="{./@deviceid}">
                <name>
                  <xsl:choose>
                    <xsl:when test="./@nickname != ''">
                      <xsl:value-of select="./@nickname"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="./@model"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </name>
                <model>
                  <xsl:value-of select="./@model"/>
                </model>
              </divecomputer>
            </xsl:for-each>
          </equipment>
        </owner>
        <xsl:for-each select="xt:node-set($buddies)/token[generate-id() = generate-id(key('tokenkey', .)[1])]">
          <xsl:sort select="." />
          <buddy>
            <xsl:attribute name="id">
              <xsl:value-of select="generate-id(key('tokenkey', .)[1])"/>
            </xsl:attribute>
            <personal>
              <xsl:choose>
                <xsl:when test="contains(., ' ')">
                  <firstname>
                    <xsl:value-of select="substring-before(., ' ')"/>
                  </firstname>
                  <lastname>
                    <xsl:value-of select="substring-after(., ' ')"/>
                  </lastname>
                </xsl:when>
                <xsl:otherwise>
                  <first_name>
                    <xsl:value-of select="."/>
                  </first_name>
                </xsl:otherwise>
              </xsl:choose>
            </personal>
          </buddy>
        </xsl:for-each>
        </diver>

      <divesite>
        <!-- There must be at least one divebase. Subsurface doesn't track this as a concept, so just assign them all to a single divebase. -->
        <divebase id="allbase">
          <name>Subsurface Divebase</name>
        </divebase>

        <xsl:apply-templates select="//site" mode="called"/>
      </divesite>

      <!-- Define all the unique gases found in the dive log -->
      <gasdefinitions>
        <!-- Get unique gas mixes from all the recorded dives -->
        <xsl:for-each select="//dive/cylinder[generate-id() = generate-id(key('gases', concat(substring-before(@o2, '.'), '/', substring-before(@he, '.')))[1])]">

          <xsl:variable name="o2">
            <xsl:choose>
              <xsl:when test="@o2 != ''">
                <xsl:value-of select="substring-before(@o2, '.')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="'21'"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>

          <xsl:variable name="he">
            <xsl:choose>
              <xsl:when test="@he != ''">
                <xsl:value-of select="substring-before(@he, '.')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="'0'"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>

          <!-- The gas definitions will have the o2 percentage as mix ID
               to ease up the reference on switchmix events. Thus we can
               just use the same references used internally on
               Subsurface.
          -->
          <mix id="mix{$o2}">
            <name>
              <xsl:value-of select="concat($o2, '/', $he)"/>
            </name>
            <o2>
              <xsl:value-of select="$o2"/>
            </o2>
            <he>
              <xsl:value-of select="$he"/>
            </he>
          </mix>
        </xsl:for-each>
      </gasdefinitions>

      <profiledata>

        <xsl:for-each select="trip">
          <repetitiongroup>
            <xsl:attribute name="id">
              <xsl:choose>
                <xsl:when test="$test != ''">
                  <xsl:value-of select="generate-id(.)" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="'testid1'" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:attribute>

            <xsl:apply-templates select="dive"/>
          </repetitiongroup>
        </xsl:for-each>
        <xsl:for-each select="dive">
          <repetitiongroup>
            <xsl:attribute name="id">
              <xsl:choose>
                <xsl:when test="string-length($units) = 0 or $units = 0">
                  <xsl:value-of select="generate-id(.)" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="'testid2'" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:attribute>
            <xsl:apply-templates select="."/>
          </repetitiongroup>
        </xsl:for-each>
      </profiledata>

      <divetrip>
        <xsl:apply-templates select="//trip"/>
      </divetrip>

    </uddf>
  </xsl:template>

  <xsl:key name="tokenkey" match="token" use="." />

  <xsl:template name="tokenize">
    <xsl:param name="string" />
    <xsl:param name="delim" />
    <xsl:choose>
      <xsl:when test="contains($string, $delim)">
      <token><xsl:value-of select="substring-before($string, $delim)" /></token>
        <xsl:call-template name="tokenize">
        <xsl:with-param name="string" select="substring-after($string,$delim)" />
        <xsl:with-param name="delim" select="$delim" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <token><xsl:value-of select="$string" /></token>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="site" mode="called">
    <site xmlns="http://www.streit.cc/uddf/3.2/">
      <xsl:attribute name="id">
        <xsl:value-of select="@uuid"/>
      </xsl:attribute>
      <name>
        <xsl:value-of select="@name"/>
      </name>
      <geography>
        <location>
          <xsl:value-of select="@name"/>
        </location>
        <latitude>
          <xsl:value-of select="substring-before(@gps, ' ')"/>
        </latitude>
        <longitude>
          <xsl:value-of select="substring-after(@gps, ' ')"/>
        </longitude>
      </geography>
      <xsl:if test="notes != ''">
        <sitedata>
          <notes>
            <xsl:value-of select="notes"/>
          </notes>
        </sitedata>
      </xsl:if>
    </site>
  </xsl:template>

  <xsl:template match="dive">
    <dive xmlns="http://www.streit.cc/uddf/3.2/">
      <xsl:attribute name="id">
        <xsl:choose>
          <xsl:when test="string-length($units) = 0 or $units = 0">
            <xsl:value-of select="generate-id(.)" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="'testid3'" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>


      <informationbeforedive>
        <xsl:variable name="buddylist">
          <xsl:call-template name="tokenize">
            <xsl:with-param name="string" select="buddy" />
            <xsl:with-param name="delim" select="', '" />
          </xsl:call-template>
        </xsl:variable>
        <xsl:for-each select="xt:node-set($buddylist)/token">
          <xsl:variable name="buddyname" select="."/>
          <xsl:for-each select="xt:node-set($buddies)/token[generate-id() = generate-id(key('tokenkey', .)[1]) and $buddyname = .]">
          <link>
            <xsl:attribute name="ref">
              <xsl:value-of select="generate-id()"/>
            </xsl:attribute>
          </link>
          </xsl:for-each>
        </xsl:for-each>
        <link>
          <xsl:attribute name="ref">
            <xsl:value-of select="@divesiteid"/>
          </xsl:attribute>
        </link>
        <divenumber>
          <xsl:value-of select="./@number"/>
        </divenumber>
        <datetime>
          <xsl:value-of select="concat(./@date, 'T', ./@time)"/>
        </datetime>
        <xsl:for-each select="divecomputer/temperature/@air|divecomputer/divetemperature/@air|divetemperature/@air">
          <airtemperature>
            <xsl:value-of select="format-number(substring-before(., ' ') + 273.15, '0.00')"/>
          </airtemperature>
        </xsl:for-each>
        <xsl:variable name="trimmedweightlist">
          <xsl:for-each select="weightsystem">
            <weight>
              <xsl:value-of select="substring-before(@weight, ' ')"/>
            </weight>
          </xsl:for-each>
        </xsl:variable>
        <xsl:if test="sum(xt:node-set($trimmedweightlist)/node()) >= 0">
          <equipmentused>
            <leadquantity>
              <xsl:value-of select="sum(xt:node-set($trimmedweightlist)/node())"/>
            </leadquantity>
          </equipmentused>
        </xsl:if>
        <xsl:if test="parent::trip">
          <tripmembership ref="trip{generate-id(..)}"/>
        </xsl:if>
      </informationbeforedive>

      <xsl:for-each select="cylinder">
        <tankdata>
          <link>
            <xsl:attribute name="ref">
              <xsl:choose>
                <xsl:when test="@o2 != ''">
                  <xsl:value-of select="concat('mix', substring-before(@o2, '.'))"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="'mix21'"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:attribute>
          </link>

          <xsl:if test="@size">

            <tankvolume>
              <xsl:value-of select="substring-before(@size, ' ')"/>
            </tankvolume>
          </xsl:if>
          <xsl:choose>
            <xsl:when test="@start">
              <tankpressurebegin>
                <xsl:value-of select="substring-before(@start, ' ') * 100000"/>
              </tankpressurebegin>
            </xsl:when>
            <xsl:otherwise>
              <tankpressurebegin>
                <xsl:value-of select="substring-before(../divecomputer[1]/sample[@pressure]/@pressure[1], ' ') * 100000"/>
              </tankpressurebegin>
            </xsl:otherwise>
          </xsl:choose>

          <xsl:choose>
            <xsl:when test="@end">
              <tankpressureend>
                <xsl:value-of select="substring-before(@end, ' ') * 100000"/>
              </tankpressureend>
            </xsl:when>
            <xsl:otherwise>
              <tankpressureend>
                <xsl:value-of select="substring-before(../divecomputer[1]/sample[@pressure][last()]/@pressure[1], ' ') * 100000"/>
              </tankpressureend>
            </xsl:otherwise>
          </xsl:choose>

        </tankdata>
      </xsl:for-each>

      <samples>

        <xsl:for-each select="divecomputer[1]/event | divecomputer[1]/sample">
          <xsl:sort select="substring-before(@time, ':') * 60 + substring-before(substring-after(@time, ':'), ' ')" data-type="number" order="ascending"/>

        <xsl:variable name="events">
          <xsl:value-of select="count(preceding-sibling::event)"/>
        </xsl:variable>

          <xsl:choose>
            <xsl:when test="name() = 'event'">

              <xsl:variable name="position">
                <xsl:value-of select="position()"/>
              </xsl:variable>

              <!-- Times of surrounding waypoints -->
              <xsl:variable name="timefirst">
                <xsl:choose>
                  <xsl:when test="../sample[position() = $position - 1 - $events]/@time != ''">
                    <xsl:call-template name="time2sec">
                      <xsl:with-param name="time">
                        <xsl:value-of select="../sample[position() = $position - 1 - $events]/@time"/>
                      </xsl:with-param>
                    </xsl:call-template>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="0"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:variable>
              <xsl:variable name="timesecond">
                <xsl:choose>
                  <xsl:when test="../sample[position() = $position - $events]/@time != ''">
                    <xsl:call-template name="time2sec">
                      <xsl:with-param name="time">
                        <xsl:value-of select="../sample[position() = $position - $events]/@time"/>
                      </xsl:with-param>
                    </xsl:call-template>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="0"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:variable>

              <!-- Depths of surrounding waypoints -->
              <xsl:variable name="depthfirst">
                <xsl:choose>
                  <xsl:when test="../sample[position() = $position - 1 - $events]/@depth != ''">
                    <xsl:call-template name="depth2mm">
                      <xsl:with-param name="depth">
                        <xsl:value-of select="../sample[position() = $position - 1 - $events]/@depth"/>
                      </xsl:with-param>
                    </xsl:call-template>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="0"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:variable>
              <xsl:variable name="depthsecond">
                <xsl:choose>
                  <xsl:when test="../sample[position() = $position - $events]/@depth != ''">
                    <xsl:call-template name="depth2mm">
                      <xsl:with-param name="depth">
                        <xsl:value-of select="../sample[position() = $position - $events]/@depth"/>
                      </xsl:with-param>
                    </xsl:call-template>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="0"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:variable>

              <xsl:variable name="time">
                <xsl:value-of select="substring-before(@time, ':') * 60 + substring-before(substring-after(@time, ':'), ' ')"/>
              </xsl:variable>

              <xsl:if test="$timesecond != $time">
                <waypoint>
                  <xsl:variable name="name">
                    <xsl:value-of select="@name"/>
                  </xsl:variable>
                  <xsl:if test="xt:node-set($eventmap)/entry[@key = $name]">
                    <alarm>
                      <xsl:value-of select="xt:node-set($eventmap)/entry[@key = $name]"/>
                    </alarm>
                  </xsl:if>

                  <depth>
                    <xsl:call-template name="approximatedepth">
                      <xsl:with-param name="timefirst">
                        <xsl:value-of select="$timefirst"/>
                      </xsl:with-param>
                      <xsl:with-param name="timesecond">
                        <xsl:value-of select="$timesecond"/>
                      </xsl:with-param>
                      <xsl:with-param name="depthfirst">
                        <xsl:value-of select="$depthfirst"/>
                      </xsl:with-param>
                      <xsl:with-param name="depthsecond">
                        <xsl:value-of select="$depthsecond"/>
                      </xsl:with-param>
                      <xsl:with-param name="timeevent">
                        <xsl:call-template name="time2sec">
                          <xsl:with-param name="time">
                            <xsl:value-of select="@time"/>
                          </xsl:with-param>
                        </xsl:call-template>
                      </xsl:with-param>
                    </xsl:call-template>
                  </depth>

                  <divetime><xsl:value-of select="$time"/></divetime>

                  <xsl:if test="@name = 'gaschange'">
                    <switchmix>
                      <xsl:attribute name="ref">
                        <xsl:value-of select="concat('mix', @value)"/>
                      </xsl:attribute>
                    </switchmix>
                  </xsl:if>

                  <xsl:if test="@name = 'heading'">
                    <heading>
                      <xsl:value-of select="@value"/>
                    </heading>
                  </xsl:if>

                </waypoint>
              </xsl:if>
            </xsl:when>
            <xsl:otherwise>

              <!-- Recorded waypoints and events occurring at the exact same time -->
              <waypoint>

                <xsl:variable name="time">
                  <xsl:value-of select="@time"/>
                </xsl:variable>

                <xsl:for-each select="preceding-sibling::event[@time = $time]">
                  <xsl:variable name="name">
                    <xsl:value-of select="@name"/>
                  </xsl:variable>
                  <xsl:if test="xt:node-set($eventmap)/entry[@key = $name]">
                    <alarm>
                      <xsl:value-of select="xt:node-set($eventmap)/entry[@key = $name]"/>
                    </alarm>
                  </xsl:if>
                </xsl:for-each>

                <depth>
                  <xsl:value-of select="round(substring-before(./@depth, ' ') * 100) div 100"/>
                </depth>

                <divetime>
                  <xsl:call-template name="time2sec">
                    <xsl:with-param name="time">
                      <xsl:value-of select="./@time"/>
                    </xsl:with-param>
                  </xsl:call-template>
                </divetime>

                <xsl:for-each select="preceding-sibling::event[@time = $time and @name='heading']/@value">
                  <heading>
                    <xsl:value-of select="."/>
                  </heading>
                </xsl:for-each>

                <xsl:for-each select="preceding-sibling::event[@time = $time and @name='gaschange']/@value">
                  <switchmix>
                    <xsl:attribute name="ref">
                      <xsl:value-of select="concat('mix', .)"/>
                    </xsl:attribute>
                  </switchmix>
                </xsl:for-each>

                <xsl:if test="./@pressure != ''">
                  <tankpressure>
                    <xsl:value-of select="substring-before(./@pressure, ' ') * 100000"/>
                  </tankpressure>
                </xsl:if>

                <xsl:if test="./@temp != ''">
                  <temperature>
                    <xsl:value-of select="format-number(substring-before(./@temp, ' ') + 273.15, '0.00')"/>
                  </temperature>
                </xsl:if>

                <!-- Recorded waypoints -->
              </waypoint>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </samples>

      <informationafterdive>
        <xsl:if test="node()/depth/@max != ''">
          <greatestdepth>
            <xsl:value-of select="substring-before(node()/depth/@max, ' ')"/>
          </greatestdepth>
        </xsl:if>
        <xsl:if test="node()/depth/@mean != ''">
          <averagedepth>
            <xsl:value-of select="substring-before(node()/depth/@mean, ' ')"/>
          </averagedepth>
        </xsl:if>
        <xsl:if test="./@duration != ''">
          <diveduration>
            <xsl:call-template name="time2sec">
              <xsl:with-param name="time">
                <xsl:value-of select="./@duration"/>
              </xsl:with-param>
            </xsl:call-template>
          </diveduration>
        </xsl:if>
        <xsl:if test="temperature/@water|divetemperature/@water != ''">
          <lowesttemperature>
            <xsl:value-of select="format-number(substring-before(temperature/@water|divetemperature/@water, ' ') + 273.15, '0.00')"/>
          </lowesttemperature>
        </xsl:if>
        <notes>
          <para>
            <xsl:value-of select="notes"/>
          </para>
          <xsl:for-each select="picture">
            <link ref="{concat(../@number, ':', @filename, '@', @offset)}"/>
          </xsl:for-each>
        </notes>
        <rating>
          <ratingvalue>
            <xsl:choose>
              <xsl:when test="./@rating = 0">
                <xsl:value-of select="'1'"/>
              </xsl:when>
              <xsl:when test="./@rating != ''">
                <xsl:value-of select="./@rating * 2"/>
              </xsl:when>
            </xsl:choose>
          </ratingvalue>
        </rating>
        <visibility>
            <xsl:choose>
              <xsl:when test="./@visibility = 1">
                <xsl:value-of select="1"/>
              </xsl:when>
              <xsl:when test="./@visibility = 2">
                <xsl:value-of select="3"/>
              </xsl:when>
              <xsl:when test="./@visibility = 3">
                <xsl:value-of select="5"/>
              </xsl:when>
              <xsl:when test="./@visibility = 4">
                <xsl:value-of select="10"/>
              </xsl:when>
              <xsl:when test="./@visibility = 5">
                <xsl:value-of select="15"/>
              </xsl:when>
            </xsl:choose>
        </visibility>
      </informationafterdive>

    </dive>
  </xsl:template>

  <xsl:template match="trip">
      <trip id="trip{generate-id()}"  xmlns="http://www.streit.cc/uddf/3.2/">
        <name><xsl:value-of select="@location"/>&#xA0;<xsl:value-of select="@date"/></name>
        <trippart>
          <name><xsl:value-of select="@location"/>&#xA0;<xsl:value-of select="@date"/></name>
          <relateddives>
            <xsl:for-each select="dive">
              <link ref="{generate-id(.)}"/>
            </xsl:for-each>
          </relateddives>
          <xsl:if test="notes != ''">
            <notes>
              <para>
                  <xsl:value-of select="notes"/>
              </para>
            </notes>
          </xsl:if>
        </trippart>
      </trip>
  </xsl:template>

<!-- Approximate waypoint depth.
     Parameters:
     timefirst    Time of the previous waypoint in seconds
     timesecond   Time of the current waypoint in seconds
     depthfirst   Depth of the first waypoint in mm
     depthsecond  Depth of the second waypoint in mm
     timeevent    Time of the event

     Returns:     Depth approximation of event in m
     -->

<xsl:template name="approximatedepth">
  <xsl:param name="timefirst"/>
  <xsl:param name="timesecond"/>
  <xsl:param name="depthfirst"/>
  <xsl:param name="depthsecond"/>
  <xsl:param name="timeevent"/>

  <xsl:value-of select="format-number((($timeevent - $timefirst) div ($timesecond - $timefirst) * ($depthsecond - $depthfirst) + $depthfirst) div 1000, '#.##')"/>

</xsl:template>

</xsl:stylesheet>