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