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 <xsl:value-of select="DiveActivity"/>
71 <xsl:if test="Comment != ''">
72 <xsl:if test="DiveActivity != ''">
73 <xsl:value-of select="': '"/>
75 <xsl:value-of select="Comment"/>
77 <xsl:if test="Equipment/Visibility != ''">
78 Visibility: <xsl:value-of select="Equipment/Visibility"/>
80 <xsl:if test="Equipment/Suit != ''">
81 Suit: <xsl:value-of select="Equipment/Suit"/>
83 <xsl:if test="Equipment/Gloves != ''">
84 Gloves: <xsl:value-of select="Equipment/Gloves"/>
86 <xsl:if test="Equipment/Weight != ''">
87 Weight: <xsl:value-of select="Equipment/Weight"/>
92 <xsl:variable name="o2">
94 <xsl:when test="DIVE/GASES/MIX/O2 != ''">
95 <xsl:value-of select="concat(DIVE/GASES/MIX/O2*100, '%')"/>
97 <xsl:otherwise>21.0%</xsl:otherwise>
100 <xsl:variable name="size">
102 <xsl:when test="Equipment/Tanks/Tank/MIX/TANK/TANKVOLUME != ''">
103 <xsl:value-of select="concat(Equipment/Tanks/Tank/MIX/TANK/TANKVOLUME * 1000, ' l')"/>
105 <xsl:otherwise>0 l</xsl:otherwise>
108 <xsl:variable name="start">
109 <xsl:variable name="number" select="Equipment/Tanks/Tank/MIX/TANK/PSTART"/>
110 <xsl:call-template name="pressure">
111 <xsl:with-param name="number" select="$number"/>
112 <xsl:with-param name="units" select="$units"/>
115 <xsl:variable name="end">
116 <xsl:variable name="number" select="Equipment/Tanks/Tank/MIX/TANK/PEND"/>
117 <xsl:call-template name="pressure">
118 <xsl:with-param name="number" select="$number"/>
119 <xsl:with-param name="units" select="$units"/>
123 <cylinder o2="{$o2}" size="{$size}" start="{$start}" end="{$end}"/>
124 <!-- end cylinder -->
126 <!-- DELTA is the sample interval -->
127 <xsl:variable name="delta">
129 <xsl:when test="DIVE/SAMPLES/DELTA != ''">
131 <xsl:when test="$units = 'si'">
132 <xsl:value-of select="DIVE/SAMPLES/DELTA"/>
135 <xsl:value-of select="round(60 * DIVE/SAMPLES/DELTA)"/>
139 <xsl:otherwise>0</xsl:otherwise>
145 <xsl:for-each select="DIVE/SAMPLES/ALARM">
146 <xsl:if test=". != 'SURFACE'">
147 <event type="" name="{.}">
148 <xsl:attribute name="time">
149 <xsl:call-template name="timeConvert">
150 <xsl:with-param name="timeSec" select="count(preceding-sibling::D) * $delta"/>
151 <xsl:with-param name="units" select="'si'"/>
159 <!-- dive sample - all the depth and temp readings -->
160 <xsl:for-each select="DIVE/SAMPLES/D">
161 <xsl:variable name="timeSec" select="(position() - 1) * $delta"/>
162 <xsl:variable name="time" select="concat(floor($timeSec div 60), ':',
163 format-number(floor($timeSec mod 60), '00'), ' min')"/>
165 <xsl:when test="name(following-sibling::*[1]) = 'TEMPERATURE'">
166 <sample time="{$time}" depth="{concat(., ' m')}"
167 temp="{following-sibling::TEMPERATURE}"/>
170 <sample time="{$time}" depth="{concat(., ' m')}"/>
180 <!-- convert pressure to bars -->
181 <xsl:template name="pressure">
182 <xsl:param name="number"/>
183 <xsl:param name="units"/>
185 <xsl:variable name="pressure">
187 <xsl:when test="$number != ''">
188 <xsl:variable name="Exp" select="substring-after($number, 'E')"/>
189 <xsl:variable name="Man" select="substring-before($number, 'E')"/>
190 <xsl:variable name="Fac" select="substring('100000000000000000000', 1, $Exp + 1)"/>
192 <xsl:when test="$Exp != ''">
193 <xsl:value-of select="(number($Man) * number($Fac))"/>
196 <xsl:value-of select="$number"/>
200 <xsl:otherwise>0</xsl:otherwise>
205 <xsl:when test="$units = 'si'">
206 <xsl:value-of select="concat(($pressure div 100000), ' bar')"/>
209 <xsl:value-of select="concat($pressure, ' bar')"/>
214 <!-- end convert pressure -->
216 <!-- convert time in seconds to minutes:seconds -->
217 <xsl:template name="timeConvert">
218 <xsl:param name="timeSec"/>
219 <xsl:param name="units"/>
222 <xsl:when test="$units = 'si'">
223 <xsl:value-of select="concat(floor(number($timeSec) div 60), ':', format-number(floor(number($timeSec) mod 60), '00'), ' min')"/>
226 <xsl:value-of select="concat(substring-before($timeSec, '.'), ':', format-number(substring-after($timeSec, '.'), '00'), ' min')"/>
230 <!-- end convert time -->