Project

General

Profile

1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!--
3
Description: parses an OGC context document to generate an array of DHTML layers
4
            that contain an <IMG> tag with src attribute set to the GetMap request.
5
Author:      adair
6
Licence:     LGPL as specified in http://www.gnu.org/copyleft/lesser.html .
7

    
8
$Id$
9
$Name$
10
-->
11

    
12
<xsl:stylesheet version="1.0" xmlns:wmc="http://www.opengis.net/context" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink">
13

    
14
  <xsl:output method="xml" omit-xml-declaration="yes"/>
15
  <xsl:strip-space elements="*"/>
16
  <!--
17
  <xsl:include href="ogcMapImgObjects.xsl" />
18
  -->
19

    
20
  <!-- The coordinates of the DHTML Layer on the HTML page -->
21
  <xsl:param name="modelId"/>
22
  <xsl:param name="widgetId"/>
23
  <xsl:param name="context">config['<xsl:value-of select="$modelId"/>']</xsl:param>
24
  <xsl:param name="extraAttributes">true</xsl:param>
25
  <xsl:param name="isIE">false</xsl:param>
26
  <xsl:param name="outputNodeId"/>
27

    
28
  <xsl:param name="bbox">
29
    <xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@minx"/>,<xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@miny"/>,
30
    <xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@maxx"/>,<xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@maxy"/>
31
  </xsl:param>
32
  <xsl:param name="width">
33
    <xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:Window/@width"/>
34
  </xsl:param>
35
  <xsl:param name="height">
36
    <xsl:value-of select="/wmc:ViewContext/wmc:General/wmc:Window/@height"/>
37
  </xsl:param>
38
  <xsl:param name="srs" select="/wmc:ViewContext/wmc:General/wmc:BoundingBox/@SRS"/>
39
  <xsl:param name="timeList"/>
40
  <xsl:param name="timeListName"/>
41
  <xsl:param name="uniqueId"/>
42
  
43
  <!-- template rule matching source root element -->
44
  <xsl:template match="/wmc:ViewContext">
45
      <div STYLE="position:absolute; width:{$width}px; height:{$height}px" ID="{$outputNodeId}">
46
        <xsl:apply-templates select="wmc:LayerList/wmc:Layer"/>
47
      </div>
48
  </xsl:template>
49
  
50
  <xsl:template match="wmc:Layer">
51
  
52
    <xsl:choose>
53
      <xsl:when test="$timeList and wmc:DimensionList/wmc:Dimension[@name='time']">
54
          <xsl:call-template name="tokenize">
55
            <xsl:with-param name="str" select="$timeList"/>
56
            <xsl:with-param name="sep" select="','"/>
57
          </xsl:call-template>
58
      </xsl:when>
59
      <xsl:otherwise>
60
        <xsl:call-template name="layerOutput"/>
61
      </xsl:otherwise>
62
    </xsl:choose>
63
    
64
  </xsl:template>
65

    
66
  <xsl:template match="wmc:StyledLayerDescriptor">
67
    <xsl:apply-templates mode="serialize" select="."/>
68
  </xsl:template>
69

    
70
  <xsl:template name="layerOutput">
71
    <xsl:param name="version">
72
        <xsl:value-of select="wmc:Server/@version"/>    
73
    </xsl:param>
74
    <xsl:param name="baseUrl">
75
        <xsl:value-of select="wmc:Server/wmc:OnlineResource/@xlink:href"/>    
76
    </xsl:param>
77
    <xsl:param name="timestamp"><xsl:value-of select="wmc:DimensionList/wmc:Dimension[@name='time']/@default"/></xsl:param>
78
    <xsl:param name="metadataUrl">
79
        <xsl:value-of select="wmc:MetadataURL/wmc:OnlineResource/@xlink:href"/>    
80
    </xsl:param>
81
    <xsl:param name="format">
82
      <xsl:choose>
83
        <xsl:when test="wmc:FormatList"><xsl:value-of select="wmc:FormatList/wmc:Format[@current='1']"/></xsl:when>
84
        <xsl:otherwise>image/gif</xsl:otherwise>
85
      </xsl:choose>
86
    </xsl:param>
87
    <xsl:param name="visibility">
88
      <xsl:choose>
89
        <xsl:when test="starts-with($isIE,'true') and $format='image/png'">hidden</xsl:when>
90
        <xsl:when test="@hidden='1'">hidden</xsl:when>
91
        <xsl:otherwise>visible</xsl:otherwise>
92
      </xsl:choose>
93
    </xsl:param>
94
    <xsl:param name="layerName">
95
      <xsl:call-template name="replace-string">
96
        <xsl:with-param name="text"><xsl:value-of select="wmc:Name"/></xsl:with-param>
97
        <xsl:with-param name="replace"><xsl:value-of select="' '"/></xsl:with-param>
98
        <xsl:with-param name="with"><xsl:value-of select="'+'"/></xsl:with-param>
99
      </xsl:call-template>
100
    </xsl:param>
101
    <xsl:variable name="styleParam">
102
      <xsl:choose>
103
        <xsl:when test="wmc:StyleList/wmc:Style[@current='1']/wmc:SLD/wmc:OnlineResource">
104
          SLD=<xsl:value-of select="wmc:StyleList/wmc:Style[@current='1']/wmc:SLD/wmc:OnlineResource/@xlink:href"/>
105
        </xsl:when>
106
        <xsl:when test="wmc:StyleList/wmc:Style[@current='1']/wmc:SLD/wmc:StyledLayerDescriptor">
107
          SLD_BODY=<xsl:apply-templates select="wmc:StyleList/wmc:Style[@current='1']/wmc:SLD/wmc:StyledLayerDescriptor" />
108
        </xsl:when>
109
        <xsl:when test="wmc:StyleList/wmc:Style[@current='1']/wmc:SLD/wmc:FeatureTypeStyle">
110
          SLD=<xsl:value-of select="wmc:StyleList/wmc:Style[@current='1']/wmc:SLD/wmc:FeatureTypeStyle"/>
111
        </xsl:when>
112
        <xsl:otherwise>
113
          STYLES=<xsl:call-template name="replace-string">
114
            <xsl:with-param name="text"><xsl:value-of select="wmc:StyleList/wmc:Style[@current='1']/wmc:Name"/></xsl:with-param>
115
            <xsl:with-param name="replace"><xsl:value-of select="' '"/></xsl:with-param>
116
            <xsl:with-param name="with"><xsl:value-of select="'+'"/></xsl:with-param>
117
          </xsl:call-template>
118
        </xsl:otherwise>
119
      </xsl:choose>
120
    </xsl:variable>
121
    <xsl:variable name="firstJoin">
122
      <xsl:choose>
123
        <xsl:when test="substring($baseUrl,string-length($baseUrl))='?'"></xsl:when>
124
        <xsl:when test="contains($baseUrl, '?')">&amp;</xsl:when> 
125
        <xsl:otherwise>?</xsl:otherwise>
126
      </xsl:choose>
127
    </xsl:variable>
128
    <xsl:variable name="mapRequest">
129
      <xsl:choose>
130
        <xsl:when test="starts-with($version, '1.0')">
131
            WMTVER=<xsl:value-of select="$version"/>&amp;REQUEST=map
132
        </xsl:when>            
133
        <xsl:otherwise>
134
            VERSION=<xsl:value-of select="$version"/>&amp;REQUEST=GetMap&amp;SERVICE=WMS
135
        </xsl:otherwise>
136
      </xsl:choose>
137
    </xsl:variable>
138

    
139
    <div>    
140
      <xsl:attribute name="style">position:absolute; visibility:<xsl:value-of select="$visibility"/>; top:0px; left:0px;</xsl:attribute>
141
      <xsl:attribute name="id">
142
        <xsl:value-of select="$modelId"/>_<xsl:value-of select="$widgetId"/>_<xsl:value-of select="$layerName"/><xsl:if test="$timestamp and wmc:DimensionList/wmc:Dimension[@name='time']">_<xsl:value-of select="$timestamp"/></xsl:if>
143
      </xsl:attribute>
144
      <xsl:if test="$timestamp and wmc:DimensionList/wmc:Dimension[@name='time']">
145
        <xsl:attribute name="time"><xsl:value-of select="$timestamp"/></xsl:attribute>
146
      </xsl:if>
147
    
148
    <xsl:element name="img">    
149
        <xsl:variable name="src">    
150
            <xsl:value-of select="$baseUrl"/>
151
            <xsl:value-of select="$firstJoin"/>
152
            <xsl:value-of select="$mapRequest"/>
153
&amp;LAYERS=<xsl:value-of select="$layerName"/>
154
   &amp;SRS=<xsl:value-of select="$srs"/>
155
  &amp;BBOX=<xsl:value-of select="$bbox"/>
156
 &amp;WIDTH=<xsl:value-of select="$width"/>
157
&amp;HEIGHT=<xsl:value-of select="$height"/>
158
&amp;FORMAT=<xsl:value-of select="$format"/>
159
       &amp;<xsl:value-of select="$styleParam"/>
160
&amp;TRANSPARENT=TRUE
161
        <xsl:if test="string-length($timestamp)>0"> 
162
       &amp;TIME=<xsl:value-of select="$timestamp"/>
163
        </xsl:if>
164
        &amp;UNIQUEID=<xsl:value-of select="$uniqueId"/>
165
<!--	
166
  //TBD: these still to be properly handled 
167
  //if (this.exceptions) src += '&' + 'EXCEPTIONS=' + this.exceptions;
168
  //if (this.vendorstr) src += '&' + this.vendorstr;
169
  // -->
170
        </xsl:variable>
171
        <xsl:attribute name="src">    
172
            <xsl:value-of select="translate(normalize-space($src),' ', '' )" disable-output-escaping="no"/>
173
        </xsl:attribute>
174
        <xsl:attribute name="width">
175
            <xsl:value-of select="$width"/>
176
        </xsl:attribute>
177
        <xsl:attribute name="height">
178
            <xsl:value-of select="$height"/>
179
        </xsl:attribute>
180
        <xsl:if test="starts-with($extraAttributes,'true')">
181
          <xsl:attribute name="alt">
182
              <xsl:value-of select="wmc:Title"/>
183
          </xsl:attribute>
184
          <xsl:attribute name="title">
185
              <xsl:value-of select="wmc:Title"/>
186
          </xsl:attribute>
187
          <xsl:if test="string-length($metadataUrl)>0">
188
            <xsl:attribute name="longdesc"><xsl:value-of select="$metadataUrl"/></xsl:attribute>
189
          </xsl:if>
190
        </xsl:if>
191
    </xsl:element>    
192
    </div>    
193
  </xsl:template>
194

    
195
  
196
  <xsl:template name="tokenize"> <!-- tokenize a string -->
197
   <xsl:param name="str"/> <!-- String to process -->
198
   <xsl:param name="sep"/> <!-- Legal separator character -->
199
   <xsl:choose>
200
    <xsl:when test="contains($str,$sep)"> <!-- Only tokenize if there is a separator present in the string -->
201
      <xsl:call-template name="process-token"> <!-- Process the token before the separator -->
202
        <xsl:with-param name="token" select="substring-before($str,$sep)"/>
203
      </xsl:call-template>
204
      <xsl:call-template name="tokenize">  <!-- Re-tokenize the new string which is contained after the separator -->
205
        <xsl:with-param name="str" select="substring-after($str,$sep)"/>
206
        <xsl:with-param name="sep" select="$sep"/> <!-- carriage return -->
207
      </xsl:call-template>
208
    </xsl:when>
209
    <xsl:otherwise>  <!-- If there is nothing else to tokenize, just treat the last part of the str as a regular token -->
210
      <xsl:call-template name="process-token">
211
        <xsl:with-param name="token" select="$str"/>
212
      </xsl:call-template>
213
    </xsl:otherwise>
214
   </xsl:choose>
215
  </xsl:template>
216

    
217
  <xsl:template name="process-token">  <!-- process - separate with <br> -->
218
    <xsl:param name="token"/> <!-- token to process -->
219
    <xsl:call-template name="layerOutput">
220
      <xsl:with-param name="timestamp" select="$token"/>
221
      <xsl:with-param name="visibility">hidden</xsl:with-param>
222
    </xsl:call-template>
223
  </xsl:template>
224
  
225
<!-- String replacemnent -->
226
<xsl:template name="replace-string">
227
  <xsl:param name="text"/>
228
  <xsl:param name="replace"/>
229
  <xsl:param name="with"/>
230
  <xsl:choose>
231
    <xsl:when test="contains($text,$replace)">
232
      <xsl:value-of select="substring-before($text,$replace)"/>
233
      <xsl:value-of select="$with"/>
234
      <xsl:call-template name="replace-string">
235
        <xsl:with-param name="text" select="substring-after($text,$replace)"/>
236
        <xsl:with-param name="replace" select="$replace"/>
237
        <xsl:with-param name="with" select="$with"/>
238
      </xsl:call-template>
239
    </xsl:when>
240
    <xsl:otherwise>
241
      <xsl:value-of select="$text"/>
242
    </xsl:otherwise>
243
  </xsl:choose>
244
</xsl:template>
245

    
246
<!-- escape URI -->
247
<xsl:template name="escape-uri">
248
  <xsl:param name="text"/>
249

    
250
  <xsl:param name="tmp">
251
  <xsl:call-template name="replace-string">
252
    <xsl:with-param name="text" select="$text"/>
253
    <xsl:with-param name="replace" select="' '"/>
254
    <xsl:with-param name="with" select="'%20'"/>
255
  </xsl:call-template>
256
  </xsl:param>
257

    
258
  <xsl:call-template name="replace-string">
259
    <xsl:with-param name="text" select="$tmp"/>
260
    <xsl:with-param name="replace" select="'#'"/>
261
    <xsl:with-param name="with" select="'%23'"/>
262
  </xsl:call-template>
263

    
264
</xsl:template>
265

    
266
<!-- Serialize node using escape URI -->
267
<xsl:template match="*" mode="serialize">
268
  <xsl:param name="count"><xsl:value-of select="count(*)"/></xsl:param>
269
  <xsl:param name="value"><xsl:apply-templates mode="serialize"/></xsl:param>
270

    
271
  <xsl:text/>%3C<xsl:value-of select="name()"/>
272
  <xsl:apply-templates select="@*" mode="serialize"/>%3E<xsl:text/>
273
  <xsl:choose>
274
    <xsl:when test="$count=0"> 
275
      <xsl:call-template name="escape-uri">
276
        <xsl:with-param name="text" select="$value"/>
277
      </xsl:call-template>
278
    </xsl:when>
279
    <xsl:otherwise>
280
      <xsl:value-of select="$value"/>    
281
    </xsl:otherwise>
282
  </xsl:choose>
283
  <xsl:text/>%3C/<xsl:value-of select="name()"/>%3E<xsl:text/>
284
</xsl:template>
285

    
286
<xsl:template match="@*" mode="serialize">
287
  <xsl:param name="value"><xsl:value-of select="."/></xsl:param>
288
  <!-- Attention: double quotes (%22) around parametr break it somewhere -->
289
  %20<xsl:value-of select="name()"/>=%22
290
  <xsl:call-template name="escape-uri">
291
    <xsl:with-param name="text" select="$value"/>
292
  </xsl:call-template>%22
293
</xsl:template>
294

    
295
</xsl:stylesheet>
(77-77/145)