root / projects / DailyProductionReport_1.0 / XML / Version1.0 / WITSML131 / stylesheets / Units.xsl @ 16

Revision 16, 18.8 kB (checked in by ryland, 15 years ago)
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet 
3        version="1.0" 
4        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
5        xmlns:posc="http://www.posc.org/schemas">
6
7<!-- View of the witsmlDict.xml unit of measure file -->
8
9<!--    Original: John Shields
10        24Feb04 Gary Masters: Add anchor name for derived units.
11                Add conversion formula.
12        24Mar04 Gary Masters: Convert to UnitOfMeasureDictionary V2 schema.
13        3Mar05  Gary Masters: Remove ID because it is an internal concept.
14                Move the annotation to a row.
15                Generate caseless anchors and hrefs.
16        31Oct06  Gary Masters: Flag deprecated units.
17 -->
18
19<xsl:output method="html" />
20
21<xsl:template match="/">
22        <html>
23                <head>
24                        <xsl:comment>This file was generated from the ancillary/witsmlUnitDict.xml file using</xsl:comment>
25                        <xsl:comment>the stylesheets/Units.xsl file.</xsl:comment>
26                        <title>WITSML conversions dictionary stylesheet</title>
27                </head>
28                <body>
29                <h1>WITSML conversions dictionary stylesheet</h1>
30                <br/>
31                <h1>Base Units</h1>
32                <xsl:apply-templates select="posc:UnitOfMeasureDictionary/posc:UnitsDefinition/posc:UnitOfMeasure/posc:BaseUnit">
33                        <xsl:sort select="../posc:Name"/>
34                </xsl:apply-templates>
35               
36                <h1>Derived units</h1>
37                <xsl:apply-templates select="posc:UnitOfMeasureDictionary/posc:UnitsDefinition/posc:UnitOfMeasure/posc:ConversionToBaseUnit">
38                        <xsl:sort select="../posc:Name"/>
39                </xsl:apply-templates>
40
41                </body>
42        </html>
43
44</xsl:template>
45
46
47<xsl:template match="posc:BaseUnit">
48        <h2><xsl:apply-templates select="../posc:CatalogSymbol" mode="baseUnitName"/>
49                <xsl:value-of select="../posc:Name" />
50        </h2>
51        <p align="center">
52                <table border="1" cellpadding="0" cellspacing="0" width="98%" >
53                        <tr>
54                                <td width="15%"><strong>Annotation</strong></td>
55                                <td>
56                                        <xsl:value-of select="../@annotation" />
57                                </td>
58                        </tr>
59                        <tr>
60                                <td width="15%"><strong>Description</strong></td>
61                                <td>
62                                        <xsl:choose>
63                                                <xsl:when test="posc:Description">
64                                                        <xsl:value-of select="posc:Description"/>
65                                                </xsl:when>
66                                                <xsl:otherwise>
67                                                        <xsl:text> </xsl:text> 
68                                                </xsl:otherwise>
69                                        </xsl:choose>
70                                </td>
71                        </tr>
72                        <tr>
73                                <td><strong>Origin</strong></td>
74                                <td><xsl:value-of select="../posc:CatalogName"/></td>
75                        </tr>
76                </table>
77        </p>
78</xsl:template>
79
80
81<xsl:template match="posc:ConversionToBaseUnit">
82        <h2>
83                <xsl:apply-templates select="../posc:CatalogSymbol" mode="baseUnitName"/>
84                <xsl:value-of select="../posc:Name"/>
85                <xsl:if test="../posc:Deprecated != ''"> [DEPRECATED]</xsl:if>
86        </h2>
87
88        <p align="center">
89                <table border="1" cellpadding="0" cellspacing="0" width="98%" >
90                        <tr>
91                                <td width="15%"><strong>Annotation</strong></td>
92                                <td>
93                                        <xsl:value-of select="../@annotation" />
94                                </td>
95                        </tr>
96                        <tr>
97                                <td width="15%"><strong>Base unit</strong></td>
98                                <td>
99                                        <xsl:apply-templates select="." mode="baseUnitRef"/>
100                                </td>
101                        </tr>
102                        <tr>
103                                <td>
104                                        <strong>Conversion</strong>
105                                        <xsl:if test="posc:Factor">
106                                                (factor)
107                                        </xsl:if>
108                                        <xsl:if test="posc:Fraction">
109                                                (fraction)
110                                        </xsl:if>
111                                        <xsl:if test="posc:Formula">
112                                                (formula)
113                                        </xsl:if>
114                                </td>
115                                <td>
116                                        <xsl:if test="posc:Factor">
117                                                <xsl:value-of select="@baseUnit"/>
118                                                <xsl:text> </xsl:text>
119                                                =
120                                                <xsl:text> </xsl:text>
121                                                <xsl:value-of select="posc:Factor"/>
122                                                <xsl:text> </xsl:text>
123                                                <xsl:value-of select="../@annotation" />
124                                        </xsl:if>
125                                        <xsl:if test="posc:Fraction">
126                                                <xsl:value-of select="@baseUnit"/>
127                                                <xsl:text> </xsl:text>
128                                                =
129                                                <xsl:text> </xsl:text>
130                                                (
131                                                <xsl:text> </xsl:text>
132                                                <xsl:value-of select="posc:Fraction/posc:Numerator"/>
133                                                <xsl:text> </xsl:text>
134                                                /
135                                                <xsl:text> </xsl:text>
136                                                <xsl:value-of select="posc:Fraction/posc:Denominator"/>
137                                                <xsl:text> </xsl:text>
138                                                )
139                                                <xsl:text> </xsl:text>
140                                                <xsl:value-of select="../@annotation" />
141                                        </xsl:if>
142                                        <xsl:if test="posc:Formula">
143                                                <xsl:value-of select="@baseUnit"/>
144                                                <xsl:text> </xsl:text>
145                                                =
146                                                <xsl:text> </xsl:text>
147                                                (
148                                                <xsl:text> </xsl:text>
149                                                <xsl:if test="posc:Formula/posc:A">
150                                                        <xsl:value-of select="posc:Formula/posc:A"/> 
151                                                </xsl:if>
152                                                <xsl:if test="posc:Formula/posc:B">
153                                                <xsl:text> </xsl:text>
154                                                        +
155                                                <xsl:text> </xsl:text>
156                                                        <xsl:value-of select="posc:Formula/posc:B"/>
157                                                        <xsl:text> </xsl:text>
158                                                        <xsl:value-of select="../@annotation" /> 
159                                                </xsl:if>
160                                                <xsl:text> </xsl:text>
161                                                )
162                                                <xsl:if test="posc:Formula/posc:C">
163                                                        <xsl:choose>
164                                                                <xsl:when test="posc:Formula/posc:D">
165                                                                        <xsl:text> </xsl:text>
166                                                                        /
167                                                                        <xsl:text> </xsl:text>
168                                                                        (
169                                                                        <xsl:text> </xsl:text>
170                                                                        <xsl:value-of select="posc:Formula/posc:C"/>
171                                                                        <xsl:text> </xsl:text>
172                                                                        +
173                                                                        <xsl:text> </xsl:text>
174                                                                        <xsl:value-of select="posc:Formula/posc:D"/>
175                                                                        <xsl:text> </xsl:text>
176                                                                        <xsl:value-of select="../@annotation" />
177                                                                        )
178                                                                </xsl:when>
179                                                                <xsl:when test="posc:Formula/posc:C != 1">
180                                                                        /
181                                                                        <xsl:text> </xsl:text>
182                                                                        <xsl:value-of select="posc:Formula/posc:C"/>
183                                                                </xsl:when>
184                                                        </xsl:choose>
185                                                </xsl:if>
186                                        </xsl:if>
187                                </td>
188                        </tr>
189                        <tr>
190                                <td><strong>Origin</strong></td>
191                                <td><xsl:value-of select="../posc:CatalogName"/></td>
192                        </tr>
193                </table>
194        </p>
195
196</xsl:template>
197
198
199
200        <xsl:template match="*" mode="baseUnitName">
201                <xsl:call-template name="uomRefString">
202                        <xsl:with-param name="string" select="."/>
203                        <xsl:with-param name="mode" select="'name'"/>
204                </xsl:call-template>
205        </xsl:template>
206
207
208        <xsl:template match="*" mode="baseUnitRef">
209                <xsl:call-template name="uomRefString">
210                        <xsl:with-param name="string" select="@baseUnit"/>
211                        <xsl:with-param name="mode" select="'href'"/>
212                </xsl:call-template>
213        </xsl:template>
214
215
216        <!-- Template to create a name anchor or to create an href to a uom in the WITSML unit file. -->
217        <!-- Add an underscore in front of Uppercase characters in the string. -->
218        <!-- Also substitute T (times) and P (per) for period (.) and slash (/). -->
219        <xsl:template name="uomRefString">
220                <xsl:param name="string" select="@uom"/>    <!-- The uom string. -->
221                <xsl:param name="index"  select="1"/>       <!-- The start index in the string. -->
222                <xsl:param name="mode"   select="'href'"/>  <!-- 'href' or 'name'. -->
223                <xsl:param name="path"   select="''"/>      <!-- Path to the unit file. Only relevant to 'href'. -->
224                <xsl:choose>
225                        <xsl:when test="not($string)">
226                        <!-- For whatever reason, this value does not have a uom. -->
227                        <!-- It may be a unitless quantity or an indexed parameter with an optional uom. -->
228                        </xsl:when>
229                        <xsl:when test="$index > string-length($string)">
230                                -------- This is a bad call ----------
231                                string='<xsl:value-of select="$string"/>'
232                                index='<xsl:value-of select="$index"/>'
233                                mode='<xsl:value-of select="$mode"/>'
234                                path='<xsl:value-of select="$path"/>'
235                        </xsl:when>
236                        <xsl:otherwise>
237                                <xsl:call-template name="_nextChar">
238                                        <xsl:with-param name="string" select="$string"/>
239                                        <xsl:with-param name="index" select="$index"/>
240                                        <xsl:with-param name="mode" select="$mode"/>
241                                        <xsl:with-param name="original" select="$string"/>
242                                        <xsl:with-param name="path" select="$path"/>
243                                </xsl:call-template>
244                        </xsl:otherwise>
245                </xsl:choose>
246        </xsl:template>
247        <!--Template to examine the next character for an upper case letter. -->
248        <xsl:template name="_nextChar">
249                <xsl:param name="string"/>
250                <xsl:param name="index"/>
251                <xsl:param name="mode"/>
252                <xsl:param name="original"/>
253                <xsl:param name="path"/>
254                <xsl:variable name="char"><xsl:value-of select="substring($string,$index,1)"/></xsl:variable>
255                <xsl:variable name="len"><xsl:value-of select="string-length($string)"/></xsl:variable>
256                <xsl:choose>
257                        <xsl:when test="not($string)"/>
258                        <xsl:when test="$index > $len">
259                                <!-- We are finished -->
260                                <xsl:if test="$mode = 'href'">
261                                        <a href="{$path}#uom::{translate($string,'./','TP')}"><xsl:value-of select="$original"/></a>
262                                </xsl:if>
263                                <xsl:if test="$mode = 'name'">
264                                        <a name="uom::{translate($string,'./','TP')}"/>
265                                </xsl:if>
266                        </xsl:when>
267                        <xsl:when test="$char='A'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
268                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
269                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
270                                                   </xsl:call-template></xsl:when>
271                        <xsl:when test="$char='B'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
272                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
273                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
274                                                   </xsl:call-template></xsl:when>
275                        <xsl:when test="$char='C'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
276                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
277                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
278                                                   </xsl:call-template></xsl:when>
279                        <xsl:when test="$char='D'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
280                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
281                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
282                                                   </xsl:call-template></xsl:when>
283                        <xsl:when test="$char='E'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
284                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
285                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
286                                                   </xsl:call-template></xsl:when>
287                        <xsl:when test="$char='F'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
288                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
289                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
290                                                   </xsl:call-template></xsl:when>
291                        <xsl:when test="$char='G'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
292                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
293                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
294                                                   </xsl:call-template></xsl:when>
295                        <xsl:when test="$char='H'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
296                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
297                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
298                                                   </xsl:call-template></xsl:when>
299                        <xsl:when test="$char='I'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
300                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
301                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
302                                                   </xsl:call-template></xsl:when>
303                        <xsl:when test="$char='J'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
304                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
305                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
306                                                   </xsl:call-template></xsl:when>
307                        <xsl:when test="$char='K'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
308                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
309                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
310                                                   </xsl:call-template></xsl:when>
311                        <xsl:when test="$char='L'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
312                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
313                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
314                                                   </xsl:call-template></xsl:when>
315                        <xsl:when test="$char='M'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
316                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
317                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
318                                                   </xsl:call-template></xsl:when>
319                        <xsl:when test="$char='N'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
320                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
321                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
322                                                   </xsl:call-template></xsl:when>
323                        <xsl:when test="$char='O'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
324                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
325                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
326                                                   </xsl:call-template></xsl:when>
327                        <xsl:when test="$char='P'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
328                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
329                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
330                                                   </xsl:call-template></xsl:when>
331                        <xsl:when test="$char='Q'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
332                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
333                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
334                                                   </xsl:call-template></xsl:when>
335                        <xsl:when test="$char='R'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
336                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
337                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
338                                                   </xsl:call-template></xsl:when>
339                        <xsl:when test="$char='S'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
340                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
341                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
342                                                   </xsl:call-template></xsl:when>
343                        <xsl:when test="$char='T'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
344                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
345                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
346                                                   </xsl:call-template></xsl:when>
347                        <xsl:when test="$char='U'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
348                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
349                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
350                                                   </xsl:call-template></xsl:when>
351                        <xsl:when test="$char='V'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
352                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
353                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
354                                                   </xsl:call-template></xsl:when>
355                        <xsl:when test="$char='W'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
356                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
357                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
358                                                   </xsl:call-template></xsl:when>
359                        <xsl:when test="$char='X'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
360                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
361                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
362                                                   </xsl:call-template></xsl:when>
363                        <xsl:when test="$char='Y'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
364                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
365                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
366                                                   </xsl:call-template></xsl:when>
367                        <xsl:when test="$char='Z'"><xsl:call-template name="_insertChar"><xsl:with-param name="string" select="$string"/>
368                                                   <xsl:with-param name="index" select="$index"/><xsl:with-param name="mode" select="$mode"/>
369                                                   <xsl:with-param name="original" select="$original"/><xsl:with-param name="path" select="$path"/>
370                                                   </xsl:call-template></xsl:when>
371                        <xsl:otherwise>
372                                <xsl:call-template name="_nextChar">
373                                        <xsl:with-param name="string" select="$string"/>
374                                        <xsl:with-param name="index" select="$index +1"/>
375                                        <xsl:with-param name="mode" select="$mode"/>
376                                        <xsl:with-param name="original" select="$original"/>
377                                        <xsl:with-param name="path" select="$path"/>
378                                </xsl:call-template>
379                        </xsl:otherwise>
380                </xsl:choose>
381        </xsl:template>
382        <!--Template to insert an underscore at the current index while calling _nextChar. -->
383        <xsl:template name="_insertChar">
384                <xsl:param name="string"/>
385                <xsl:param name="index"/>
386                <xsl:param name="mode"/>
387                <xsl:param name="original"/>
388                <xsl:param name="path"/>
389                <xsl:variable name="len"><xsl:value-of select="string-length($string)"/></xsl:variable>
390                <xsl:call-template name="_nextChar">
391                        <xsl:with-param name="string" select="concat(substring($string,1,$index - 1),'_',substring($string,$index,$len - $index +1))"/>
392                        <xsl:with-param name="index" select="$index +2"/>
393                        <xsl:with-param name="mode" select="$mode"/>
394                        <xsl:with-param name="original" select="$original"/>
395                        <xsl:with-param name="path" select="$path"/>
396                </xsl:call-template>
397        </xsl:template>
398
399</xsl:stylesheet>
Note: See TracBrowser for help on using the browser.