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