]> git.tdb.fi Git - ext/subsurface.git/blob - xslt/SuuntoSDM.xslt
Suunto SDE updates, take 178: add weight and visibility info
[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       </notes>
84
85 <!-- FIXME: add support for multiple cylinders, need sample data -->
86       <cylinder>
87       <xsl:attribute name="o2">
88         <xsl:choose>
89           <xsl:when test="O2PCT != ''">
90             <xsl:value-of select="concat(O2PCT, '%')"/>
91           </xsl:when>
92           <xsl:otherwise>21.0%</xsl:otherwise>
93         </xsl:choose>
94       </xsl:attribute>
95       <xsl:if test="HEPCT != ''">
96         <xsl:attribute name="he">
97           <xsl:value-of select="concat(HEPCT, '%')"/>
98         </xsl:attribute>
99       </xsl:if>
100       <xsl:if test="CYLINDERDESCRIPTION != ''">
101         <xsl:attribute name="description">
102           <xsl:value-of select="CYLINDERDESCRIPTION"/>
103         </xsl:attribute>
104       </xsl:if>
105       <xsl:if test="CYLINDERSIZE != ''">
106         <xsl:attribute name="size">
107             <xsl:choose>
108               <xsl:when test="CYLINDERUNITS = '0'">
109                 <xsl:value-of select="concat(CYLINDERSIZE, ' l')"/>
110               </xsl:when>
111               <xsl:otherwise>
112                 <xsl:call-template name="cuft2l">
113                   <xsl:with-param name="size" select="CYLINDERSIZE"/>
114                   <xsl:with-param name="pressure" select="CYLINDERWORKPRESSURE"/>
115                 </xsl:call-template>
116               </xsl:otherwise>
117             </xsl:choose>
118         </xsl:attribute>
119       </xsl:if>
120       <xsl:attribute name="start">
121         <xsl:variable name="number" select="CYLINDERSTARTPRESSURE"/>
122         <xsl:call-template name="pressure">
123           <xsl:with-param name="number" select="$number"/>
124           <xsl:with-param name="units" select="$units"/>
125         </xsl:call-template>
126       </xsl:attribute>
127       <xsl:attribute name="end">
128         <xsl:variable name="number" select="CYLINDERENDPRESSURE"/>
129         <xsl:call-template name="pressure">
130           <xsl:with-param name="number" select="$number"/>
131           <xsl:with-param name="units" select="$units"/>
132         </xsl:call-template>
133       </xsl:attribute>
134       <xsl:if test="CYLINDERWORKPRESSURE != '0'">
135         <xsl:attribute name="workpressure">
136           <xsl:variable name="number" select="CYLINDERWORKPRESSURE"/>
137           <xsl:call-template name="pressure">
138             <xsl:with-param name="number" select="$number"/>
139             <xsl:with-param name="units" select="$units"/>
140           </xsl:call-template>
141         </xsl:attribute>
142       </xsl:if>
143       </cylinder>
144
145       <!-- DELTA is the sample interval -->
146       <xsl:variable name="delta">
147         <xsl:choose>
148           <xsl:when test="SAMPLEINTERVAL != ''">
149             <xsl:value-of select="SAMPLEINTERVAL"/>
150           </xsl:when>
151           <xsl:otherwise>0</xsl:otherwise>
152         </xsl:choose>
153       </xsl:variable>
154       <!-- end delta -->
155
156       <!-- gas change -->
157 <!-- FIXME: test this with proper data -->
158       <xsl:for-each select="GASCHANGE">
159         <xsl:if test="MIXTIME != '0'">
160           <event name="gaschange">
161             <xsl:attribute name="value">
162               <xsl:value-of select="MIXVALUE" />
163             </xsl:attribute>
164             <xsl:attribute name="time">
165               <xsl:call-template name="timeConvert">
166                 <xsl:with-param name="timeSec" select="MIXTIME"/>
167                 <xsl:with-param name="units" select="'si'"/>
168               </xsl:call-template>
169             </xsl:attribute>
170           </event>
171         </xsl:if>
172       </xsl:for-each>
173       <!-- end gas change-->
174
175       <!-- dive sample - all the depth and temp readings -->
176       <xsl:for-each select="SAMPLE">
177         <xsl:choose>
178           <xsl:when test="BOOKMARK = ''">
179             <sample>
180               <xsl:attribute name="time">
181                 <xsl:call-template name="timeConvert">
182                   <xsl:with-param name="timeSec" select="SAMPLETIME"/>
183                   <xsl:with-param name="units" select="'si'"/>
184                 </xsl:call-template>
185               </xsl:attribute>
186               <xsl:attribute name="depth">
187                 <xsl:value-of select="concat(DEPTH, ' m')"/>
188               </xsl:attribute>
189               <xsl:attribute name="temp">
190                 <xsl:value-of select="TEMPERATURE"/>
191               </xsl:attribute>
192               <xsl:attribute name="pressure">
193                 <xsl:call-template name="pressure">
194                   <xsl:with-param name="number" select="PRESSURE"/>
195                   <xsl:with-param name="units" select="$units"/>
196                 </xsl:call-template>
197               </xsl:attribute>
198             </sample>
199           </xsl:when>
200           <xsl:otherwise>
201             <xsl:if test="BOOKMARK != 'Surface'">
202               <event name="{BOOKMARK}">
203                 <xsl:attribute name="time">
204                   <xsl:call-template name="timeConvert">
205                     <xsl:with-param name="timeSec" select="SAMPLETIME"/>
206                     <xsl:with-param name="units" select="'si'"/>
207                   </xsl:call-template>
208                 </xsl:attribute>
209               </event>
210             </xsl:if>
211           </xsl:otherwise>
212         </xsl:choose>
213       </xsl:for-each>
214       <!-- dive sample -->
215
216     </dive>
217   </xsl:template>
218   <!-- end JDive -->
219
220   <!-- convert pressure to bars -->
221   <xsl:template name="pressure">
222     <xsl:param name="number"/>
223     <xsl:param name="units"/>
224
225     <xsl:choose>
226       <xsl:when test="$number != ''">
227         <xsl:value-of select="concat(($number div 1000), ' bar')"/>
228       </xsl:when>
229       <xsl:otherwise>0</xsl:otherwise>
230     </xsl:choose>
231   </xsl:template>
232   <!-- end convert pressure -->
233
234   <!-- convert cuft to liters-->
235   <xsl:template name="cuft2l">
236     <xsl:param name="size"/>
237     <xsl:param name="pressure"/>
238     <xsl:choose>
239       <xsl:when test="$pressure != '0'">
240         <xsl:value-of select="concat(format-number((($size*28.3168466) div ($pressure div 1013.25)), '0.000'), ' l')" />
241       </xsl:when>
242       <xsl:otherwise>0</xsl:otherwise>
243     </xsl:choose>
244   </xsl:template>
245   <!-- end cuft2l -->
246
247   <!-- convert time in seconds to minutes:seconds -->
248   <xsl:template name="timeConvert">
249     <xsl:param name="timeSec"/>
250     <xsl:param name="units"/>
251
252     <xsl:choose>
253       <xsl:when test="$timeSec = '0'">
254         <xsl:value-of select="'0:00 min'" />
255       </xsl:when>
256       <xsl:when test="$units = 'si'">
257         <xsl:value-of select="concat(floor(number($timeSec) div 60), ':', format-number(floor(number($timeSec) mod 60), '00'), ' min')"/>
258       </xsl:when>
259       <xsl:otherwise>
260         <xsl:value-of select="concat(substring-before($timeSec, '.'), ':', format-number(substring-after($timeSec, '.'), '00'), ' min')"/>
261       </xsl:otherwise>
262     </xsl:choose>
263   </xsl:template>
264   <!-- end convert time -->
265
266   <!-- convert date from dotted notation to dash notation -->
267   <xsl:template name="dateConvert">
268     <xsl:param name="date" />
269     <xsl:value-of select="concat(substring($date,7,4), '-', substring($date,4,2), '-', substring($date,1,2))" />
270   </xsl:template>
271 </xsl:stylesheet>