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"/>
6 <xsl:template match="/">
8 <program name="subsurface" version="1"/>
9 <xsl:apply-templates select="/JDiveLog/JDive"/>
13 <xsl:template match="JDive">
14 <xsl:variable name="units" select="UNITS"/>
16 <dive number="{DiveNum}">
17 <xsl:attribute name="date">
18 <xsl:value-of select="concat(DATE/YEAR,'-',format-number(DATE/MONTH,
19 '00'), '-', format-number(DATE/DAY, '00'))"/>
22 <xsl:attribute name="time">
23 <xsl:value-of select="concat(format-number(TIME/HOUR, '00'), ':',
24 format-number(TIME/MINUTE, '00'))"/>
27 <xsl:attribute name="duration">
28 <xsl:call-template name="timeConvert">
29 <xsl:with-param name="timeSec" select="Duration"/>
30 <xsl:with-param name="units" select="$units"/>
35 <xsl:when test="Average_Depth != ''">
36 <depth max="{concat(Depth,' m')}" mean="{concat(Average_Depth, ' m')}"/>
39 <depth max="{concat(Depth,' m')}"/>
43 <xsl:if test="TEMPERATURE != ''">
45 <xsl:when test="$units = 'si'">
46 <temperature water="{concat(format-number(TEMPERATURE - 273.15, '00.0'), ' C')}"/>
49 <temperature water="{concat(TEMPERATURE, ' C')}"/>
54 <xsl:if test="diveSiteId != ''">
55 <xsl:variable name="diveSite" select="diveSiteId"/>
57 <xsl:value-of select="concat(/JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$diveSite]/country, ' ', /JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$diveSite]/state, ' ', /JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$diveSite]/city, ' ', /JDiveLog/Masterdata/DiveSites/DiveSite[privateId=$diveSite]/spot)"/>
63 <xsl:value-of select="Buddy"/>
67 <xsl:if test="Equipment/Suit != ''">
69 <xsl:value-of select="Equipment/Suit"/>
71 <xsl:value-of select="Equipment/Suit"/>
74 <xsl:if test="Equipment/Weight != ''">
76 <xsl:attribute name="weight">
77 <xsl:value-of select="Equipment/Weight"/>
83 <xsl:if test="DiveActivity != ''">
84 Diveactivity: <xsl:value-of select="DiveActivity"/>
86 <xsl:if test="DiveType != ''">
87 Divetype: <xsl:value-of select="DiveType"/>
89 <xsl:if test="Equipment/Visibility != ''">
90 Visibility: <xsl:value-of select="Equipment/Visibility"/>
92 <xsl:if test="Equipment/Gloves != ''">
93 Gloves: <xsl:value-of select="Equipment/Gloves"/>
95 <xsl:if test="Comment != ''">
96 Comment: <xsl:value-of select="Comment"/>
101 <xsl:for-each select="Equipment/Tanks/Tank">
103 <xsl:attribute name="o2">
105 <xsl:when test="MIX/O2 != ''">
106 <xsl:value-of select="concat(MIX/O2*100, '%')"/>
108 <xsl:otherwise>21.0%</xsl:otherwise>
111 <xsl:if test="MIX/HE != '0.0'">
112 <xsl:attribute name="he">
113 <xsl:value-of select="concat(MIX/HE*100, '%')"/>
116 <xsl:attribute name="size">
118 <xsl:when test="MIX/TANK/TANKVOLUME != ''">
119 <xsl:value-of select="concat(MIX/TANK/TANKVOLUME * 1000, ' l')"/>
121 <xsl:otherwise>0 l</xsl:otherwise>
124 <xsl:attribute name="start">
125 <xsl:variable name="number" select="MIX/TANK/PSTART"/>
126 <xsl:call-template name="pressure">
127 <xsl:with-param name="number" select="$number"/>
128 <xsl:with-param name="units" select="$units"/>
131 <xsl:attribute name="end">
132 <xsl:variable name="number" select="MIX/TANK/PEND"/>
133 <xsl:call-template name="pressure">
134 <xsl:with-param name="number" select="$number"/>
135 <xsl:with-param name="units" select="$units"/>
140 <!-- end cylinder -->
142 <!-- DELTA is the sample interval -->
143 <xsl:variable name="delta">
145 <xsl:when test="DIVE/SAMPLES/DELTA != ''">
147 <xsl:when test="$units = 'si'">
148 <xsl:value-of select="DIVE/SAMPLES/DELTA"/>
151 <xsl:value-of select="round(60 * DIVE/SAMPLES/DELTA)"/>
155 <xsl:otherwise>0</xsl:otherwise>
161 <xsl:for-each select="DIVE/SAMPLES/ALARM">
162 <xsl:if test=". != 'SURFACE'">
163 <event type="" name="{.}">
164 <xsl:attribute name="time">
165 <xsl:call-template name="timeConvert">
166 <xsl:with-param name="timeSec" select="count(preceding-sibling::D) * $delta"/>
167 <xsl:with-param name="units" select="'si'"/>
176 <xsl:for-each select="DIVE/SAMPLES/SWITCH">
177 <event name="gaschange">
178 <xsl:attribute name="time">
179 <xsl:call-template name="timeConvert">
180 <xsl:with-param name="timeSec" select="count(preceding-sibling::D) * $delta"/>
181 <xsl:with-param name="units" select="'si'"/>
184 <xsl:attribute name="value">
185 <xsl:value-of select="ancestor::DIVE/GASES/MIX[MIXNAME=current()]/O2 * 100" />
189 <!-- end gas change -->
191 <!-- dive sample - all the depth and temp readings -->
192 <xsl:for-each select="DIVE/SAMPLES/D">
193 <xsl:variable name="timeSec" select="(position() - 1) * $delta"/>
194 <xsl:variable name="time" select="concat(floor($timeSec div 60), ':',
195 format-number(floor($timeSec mod 60), '00'), ' min')"/>
197 <xsl:when test="name(following-sibling::*[1]) = 'TEMPERATURE'">
198 <sample time="{$time}" depth="{concat(., ' m')}"
199 temp="{following-sibling::TEMPERATURE}"/>
202 <sample time="{$time}" depth="{concat(., ' m')}"/>
212 <!-- convert pressure to bars -->
213 <xsl:template name="pressure">
214 <xsl:param name="number"/>
215 <xsl:param name="units"/>
217 <xsl:variable name="pressure">
219 <xsl:when test="$number != ''">
220 <xsl:variable name="Exp" select="substring-after($number, 'E')"/>
221 <xsl:variable name="Man" select="substring-before($number, 'E')"/>
222 <xsl:variable name="Fac" select="substring('100000000000000000000', 1, $Exp + 1)"/>
224 <xsl:when test="$Exp != ''">
225 <xsl:value-of select="(number($Man) * number($Fac))"/>
228 <xsl:value-of select="$number"/>
232 <xsl:otherwise>0</xsl:otherwise>
237 <xsl:when test="$units = 'si'">
238 <xsl:value-of select="concat(($pressure div 100000), ' bar')"/>
241 <xsl:value-of select="concat($pressure, ' bar')"/>
246 <!-- end convert pressure -->
248 <!-- convert time in seconds to minutes:seconds -->
249 <xsl:template name="timeConvert">
250 <xsl:param name="timeSec"/>
251 <xsl:param name="units"/>
254 <xsl:when test="$units = 'si'">
255 <xsl:value-of select="concat(floor(number($timeSec) div 60), ':', format-number(floor(number($timeSec) mod 60), '00'), ' min')"/>
258 <xsl:value-of select="concat(substring-before($timeSec, '.'), ':', format-number(substring-after($timeSec, '.'), '00'), ' min')"/>
262 <!-- end convert time -->