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"/>
68 <xsl:if test="DiveActivity != ''">
69 Diveactivity: <xsl:value-of select="DiveActivity"/>
71 <xsl:if test="DiveType != ''">
72 Divetype: <xsl:value-of select="DiveType"/>
74 <xsl:if test="Equipment/Visibility != ''">
75 Visibility: <xsl:value-of select="Equipment/Visibility"/>
77 <xsl:if test="Equipment/Suit != ''">
78 Suit: <xsl:value-of select="Equipment/Suit"/>
80 <xsl:if test="Equipment/Gloves != ''">
81 Gloves: <xsl:value-of select="Equipment/Gloves"/>
83 <xsl:if test="Equipment/Weight != ''">
84 Weight: <xsl:value-of select="Equipment/Weight"/>
86 <xsl:if test="Comment != ''">
87 Comment: <xsl:value-of select="Comment"/>
92 <xsl:for-each select="Equipment/Tanks/Tank">
94 <xsl:attribute name="o2">
96 <xsl:when test="MIX/O2 != ''">
97 <xsl:value-of select="concat(MIX/O2*100, '%')"/>
99 <xsl:otherwise>21.0%</xsl:otherwise>
102 <xsl:if test="MIX/HE != '0.0'">
103 <xsl:attribute name="he">
104 <xsl:value-of select="concat(MIX/HE*100, '%')"/>
107 <xsl:attribute name="size">
109 <xsl:when test="MIX/TANK/TANKVOLUME != ''">
110 <xsl:value-of select="concat(MIX/TANK/TANKVOLUME * 1000, ' l')"/>
112 <xsl:otherwise>0 l</xsl:otherwise>
115 <xsl:attribute name="start">
116 <xsl:variable name="number" select="MIX/TANK/PSTART"/>
117 <xsl:call-template name="pressure">
118 <xsl:with-param name="number" select="$number"/>
119 <xsl:with-param name="units" select="$units"/>
122 <xsl:attribute name="end">
123 <xsl:variable name="number" select="MIX/TANK/PEND"/>
124 <xsl:call-template name="pressure">
125 <xsl:with-param name="number" select="$number"/>
126 <xsl:with-param name="units" select="$units"/>
131 <!-- end cylinder -->
133 <!-- DELTA is the sample interval -->
134 <xsl:variable name="delta">
136 <xsl:when test="DIVE/SAMPLES/DELTA != ''">
138 <xsl:when test="$units = 'si'">
139 <xsl:value-of select="DIVE/SAMPLES/DELTA"/>
142 <xsl:value-of select="round(60 * DIVE/SAMPLES/DELTA)"/>
146 <xsl:otherwise>0</xsl:otherwise>
152 <xsl:for-each select="DIVE/SAMPLES/ALARM">
153 <xsl:if test=". != 'SURFACE'">
154 <event type="" name="{.}">
155 <xsl:attribute name="time">
156 <xsl:call-template name="timeConvert">
157 <xsl:with-param name="timeSec" select="count(preceding-sibling::D) * $delta"/>
158 <xsl:with-param name="units" select="'si'"/>
167 <xsl:for-each select="DIVE/SAMPLES/SWITCH">
168 <event name="gaschange">
169 <xsl:attribute name="time">
170 <xsl:call-template name="timeConvert">
171 <xsl:with-param name="timeSec" select="count(preceding-sibling::D) * $delta"/>
172 <xsl:with-param name="units" select="'si'"/>
175 <xsl:attribute name="value">
176 <xsl:value-of select="ancestor::DIVE/GASES/MIX[MIXNAME=current()]/O2 * 100" />
180 <!-- end gas change -->
182 <!-- dive sample - all the depth and temp readings -->
183 <xsl:for-each select="DIVE/SAMPLES/D">
184 <xsl:variable name="timeSec" select="(position() - 1) * $delta"/>
185 <xsl:variable name="time" select="concat(floor($timeSec div 60), ':',
186 format-number(floor($timeSec mod 60), '00'), ' min')"/>
188 <xsl:when test="name(following-sibling::*[1]) = 'TEMPERATURE'">
189 <sample time="{$time}" depth="{concat(., ' m')}"
190 temp="{following-sibling::TEMPERATURE}"/>
193 <sample time="{$time}" depth="{concat(., ' m')}"/>
203 <!-- convert pressure to bars -->
204 <xsl:template name="pressure">
205 <xsl:param name="number"/>
206 <xsl:param name="units"/>
208 <xsl:variable name="pressure">
210 <xsl:when test="$number != ''">
211 <xsl:variable name="Exp" select="substring-after($number, 'E')"/>
212 <xsl:variable name="Man" select="substring-before($number, 'E')"/>
213 <xsl:variable name="Fac" select="substring('100000000000000000000', 1, $Exp + 1)"/>
215 <xsl:when test="$Exp != ''">
216 <xsl:value-of select="(number($Man) * number($Fac))"/>
219 <xsl:value-of select="$number"/>
223 <xsl:otherwise>0</xsl:otherwise>
228 <xsl:when test="$units = 'si'">
229 <xsl:value-of select="concat(($pressure div 100000), ' bar')"/>
232 <xsl:value-of select="concat($pressure, ' bar')"/>
237 <!-- end convert pressure -->
239 <!-- convert time in seconds to minutes:seconds -->
240 <xsl:template name="timeConvert">
241 <xsl:param name="timeSec"/>
242 <xsl:param name="units"/>
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')"/>
249 <xsl:value-of select="concat(substring-before($timeSec, '.'), ':', format-number(substring-after($timeSec, '.'), '00'), ' min')"/>
253 <!-- end convert time -->