]> git.tdb.fi Git - ext/subsurface.git/blob - xslt/SuuntoSDM.xslt
Fix profile and average depth for freedives
[ext/subsurface.git] / xslt / SuuntoSDM.xslt
1 <?xml version="1.0"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3   <xsl:strip-space elements="*"/>
4   <xsl:output method="xml" indent="yes"/>
5
6   <xsl:template match="/">
7     <dives>
8       <program name="subsurface" version="1"/>
9       <xsl:apply-templates select="/SUUNTO/MSG"/>
10     </dives>
11   </xsl:template>
12
13   <xsl:template match="MSG">
14     <xsl:variable name="units" select="'si'"/>
15
16     <dive number="{DIVENUMBER}">
17       <xsl:attribute name="date">
18         <xsl:call-template name="dateConvert">
19           <xsl:with-param name="date" select="DATE"/>
20         </xsl:call-template>
21       </xsl:attribute>
22
23       <xsl:attribute name="time">
24         <xsl:value-of select="TIME"/>
25       </xsl:attribute>
26
27       <xsl:attribute name="duration">
28         <xsl:call-template name="timeConvert">
29           <xsl:with-param name="timeSec" select="DIVETIMESEC"/>
30           <xsl:with-param name="units" select="$units"/>
31         </xsl:call-template>
32       </xsl:attribute>
33
34       <xsl:choose>
35         <xsl:when test="MEANDEPTH != ''">
36           <depth max="{concat(MAXDEPTH,' m')}" mean="{concat(MEANDEPTH, ' m')}"/>
37         </xsl:when>
38         <xsl:otherwise>
39           <depth max="{concat(MAXDEPTH,' m')}"/>
40         </xsl:otherwise>
41       </xsl:choose>
42
43       <temperature air="{concat(AIRTEMP, ' C')}" water="{concat(WATERTEMPATEND, ' C')}"/>
44       <xsl:if test="SURFACETIME != '0'">
45         <surfacetime>
46           <xsl:call-template name="timeConvert">
47             <xsl:with-param name="timeSec" select="SURFACETIME" />
48             <xsl:with-param name="units" select="$units" />
49           </xsl:call-template>
50         </surfacetime>
51       </xsl:if>
52       <divemaster><xsl:value-of select="DIVEMASTER" /></divemaster>
53       <buddy><xsl:value-of select="PARTNER" /></buddy>
54       <xsl:choose>
55         <xsl:when test="LOCATION != ''">
56           <location><xsl:value-of select="normalize-space(concat(LOCATION, ' ' , SITE))" /></location>
57         </xsl:when>
58         <xsl:otherwise>
59           <xsl:if test="SITE != ''">
60             <location><xsl:value-of select="SITE" /></location>
61           </xsl:if>
62         </xsl:otherwise>
63       </xsl:choose>
64
65       <xsl:if test="WEIGTH != ''">
66         <weightsystem>
67           <xsl:attribute name="weight">
68             <xsl:value-of select="concat(WEIGTH, ' kg')"/>
69           </xsl:attribute>
70         </weightsystem>
71       </xsl:if>
72
73       <notes>
74       <xsl:if test="LOGNOTES != ''">
75         <xsl:value-of select="LOGNOTES" />
76       </xsl:if>
77       <xsl:if test="WEATHER != ''">
78         Weather: <xsl:value-of select="WEATHER" />
79       </xsl:if>
80       <xsl:if test="WATERVISIBILITYDESC != ''">
81         Visibility: <xsl:value-of select="WATERVISIBILITYDESC" />
82       </xsl:if>
83       <xsl:if test="BOATNAME != ''">
84         Boat name: <xsl:value-of select="BOATNAME" />
85       </xsl:if>
86       </notes>
87
88 <!-- FIXME: add support for multiple cylinders, need sample data -->
89       <cylinder>
90       <xsl:attribute name="o2">
91         <xsl:choose>
92           <xsl:when test="O2PCT != ''">
93             <xsl:value-of select="concat(O2PCT, '%')"/>
94           </xsl:when>
95           <xsl:otherwise>21.0%</xsl:otherwise>
96         </xsl:choose>
97       </xsl:attribute>
98       <xsl:if test="HEPCT != ''">
99         <xsl:attribute name="he">
100           <xsl:value-of select="concat(HEPCT, '%')"/>
101         </xsl:attribute>
102       </xsl:if>
103       <xsl:if test="CYLINDERDESCRIPTION != ''">
104         <xsl:attribute name="description">
105           <xsl:value-of select="CYLINDERDESCRIPTION"/>
106         </xsl:attribute>
107       </xsl:if>
108       <xsl:if test="CYLINDERSIZE != ''">
109         <xsl:attribute name="size">
110             <xsl:choose>
111               <xsl:when test="CYLINDERUNITS = '0'">
112                 <xsl:value-of select="concat(CYLINDERSIZE, ' l')"/>
113               </xsl:when>
114               <xsl:otherwise>
115                 <xsl:call-template name="cuft2l">
116                   <xsl:with-param name="size" select="CYLINDERSIZE"/>
117                   <xsl:with-param name="pressure" select="CYLINDERWORKPRESSURE"/>
118                 </xsl:call-template>
119               </xsl:otherwise>
120             </xsl:choose>
121         </xsl:attribute>
122       </xsl:if>
123       <xsl:attribute name="start">
124         <xsl:variable name="number" select="CYLINDERSTARTPRESSURE"/>
125         <xsl:call-template name="pressure">
126           <xsl:with-param name="number" select="$number"/>
127           <xsl:with-param name="units" select="$units"/>
128         </xsl:call-template>
129       </xsl:attribute>
130       <xsl:attribute name="end">
131         <xsl:variable name="number" select="CYLINDERENDPRESSURE"/>
132         <xsl:call-template name="pressure">
133           <xsl:with-param name="number" select="$number"/>
134           <xsl:with-param name="units" select="$units"/>
135         </xsl:call-template>
136       </xsl:attribute>
137       <xsl:if test="CYLINDERWORKPRESSURE != '0'">
138         <xsl:attribute name="workpressure">
139           <xsl:variable name="number" select="CYLINDERWORKPRESSURE"/>
140           <xsl:call-template name="pressure">
141             <xsl:with-param name="number" select="$number"/>
142             <xsl:with-param name="units" select="$units"/>
143           </xsl:call-template>
144         </xsl:attribute>
145       </xsl:if>
146       </cylinder>
147
148       <!-- DELTA is the sample interval -->
149       <xsl:variable name="delta">
150         <xsl:choose>
151           <xsl:when test="SAMPLEINTERVAL != ''">
152             <xsl:value-of select="SAMPLEINTERVAL"/>
153           </xsl:when>
154           <xsl:otherwise>0</xsl:otherwise>
155         </xsl:choose>
156       </xsl:variable>
157       <!-- end delta -->
158
159       <!-- gas change -->
160 <!-- FIXME: test this with proper data -->
161       <xsl:for-each select="GASCHANGE">
162         <xsl:if test="MIXTIME != '0'">
163           <event name="gaschange">
164             <xsl:attribute name="value">
165               <xsl:value-of select="MIXVALUE" />
166             </xsl:attribute>
167             <xsl:attribute name="time">
168               <xsl:call-template name="timeConvert">
169                 <xsl:with-param name="timeSec" select="MIXTIME"/>
170                 <xsl:with-param name="units" select="'si'"/>
171               </xsl:call-template>
172             </xsl:attribute>
173           </event>
174         </xsl:if>
175       </xsl:for-each>
176       <!-- end gas change-->
177
178       <!-- dive sample - all the depth and temp readings -->
179       <xsl:for-each select="SAMPLE">
180         <xsl:choose>
181           <xsl:when test="BOOKMARK = ''">
182             <sample>
183               <xsl:attribute name="time">
184                 <xsl:call-template name="timeConvert">
185                   <xsl:with-param name="timeSec" select="SAMPLETIME"/>
186                   <xsl:with-param name="units" select="'si'"/>
187                 </xsl:call-template>
188               </xsl:attribute>
189               <xsl:attribute name="depth">
190                 <xsl:value-of select="concat(DEPTH, ' m')"/>
191               </xsl:attribute>
192               <xsl:attribute name="temp">
193                 <xsl:value-of select="TEMPERATURE"/>
194               </xsl:attribute>
195               <xsl:attribute name="pressure">
196                 <xsl:call-template name="pressure">
197                   <xsl:with-param name="number" select="PRESSURE"/>
198                   <xsl:with-param name="units" select="$units"/>
199                 </xsl:call-template>
200               </xsl:attribute>
201             </sample>
202           </xsl:when>
203           <xsl:otherwise>
204             <xsl:if test="BOOKMARK != 'Surface'">
205               <event name="{BOOKMARK}">
206                 <xsl:attribute name="time">
207                   <xsl:call-template name="timeConvert">
208                     <xsl:with-param name="timeSec" select="SAMPLETIME"/>
209                     <xsl:with-param name="units" select="'si'"/>
210                   </xsl:call-template>
211                 </xsl:attribute>
212               </event>
213             </xsl:if>
214           </xsl:otherwise>
215         </xsl:choose>
216       </xsl:for-each>
217       <!-- dive sample -->
218
219     </dive>
220   </xsl:template>
221   <!-- end JDive -->
222
223   <!-- convert pressure to bars -->
224   <xsl:template name="pressure">
225     <xsl:param name="number"/>
226     <xsl:param name="units"/>
227
228     <xsl:choose>
229       <xsl:when test="$number != ''">
230         <xsl:value-of select="concat(($number div 1000), ' bar')"/>
231       </xsl:when>
232       <xsl:otherwise>0</xsl:otherwise>
233     </xsl:choose>
234   </xsl:template>
235   <!-- end convert pressure -->
236
237   <!-- convert cuft to liters-->
238   <xsl:template name="cuft2l">
239     <xsl:param name="size"/>
240     <xsl:param name="pressure"/>
241     <xsl:choose>
242       <xsl:when test="$pressure != '0'">
243         <xsl:value-of select="concat(format-number((($size*28.3168466) div ($pressure div 1013.25)), '0.000'), ' l')" />
244       </xsl:when>
245       <xsl:otherwise>0</xsl:otherwise>
246     </xsl:choose>
247   </xsl:template>
248   <!-- end cuft2l -->
249
250   <!-- convert time in seconds to minutes:seconds -->
251   <xsl:template name="timeConvert">
252     <xsl:param name="timeSec"/>
253     <xsl:param name="units"/>
254
255     <xsl:choose>
256       <xsl:when test="$timeSec = '0'">
257         <xsl:value-of select="'0:00 min'" />
258       </xsl:when>
259       <xsl:when test="$units = 'si'">
260         <xsl:value-of select="concat(floor(number($timeSec) div 60), ':', format-number(floor(number($timeSec) mod 60), '00'), ' min')"/>
261       </xsl:when>
262       <xsl:otherwise>
263         <xsl:value-of select="concat(substring-before($timeSec, '.'), ':', format-number(substring-after($timeSec, '.'), '00'), ' min')"/>
264       </xsl:otherwise>
265     </xsl:choose>
266   </xsl:template>
267   <!-- end convert time -->
268
269   <!-- convert date from dotted notation to dash notation -->
270   <xsl:template name="dateConvert">
271     <xsl:param name="date" />
272     <xsl:value-of select="concat(substring($date,7,4), '-', substring($date,4,2), '-', substring($date,1,2))" />
273   </xsl:template>
274 </xsl:stylesheet>