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