Project

General

Profile

1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

    
3

    
4

    
5
<!--
6

    
7
Description: Convert <coordinates> to <coord x> <coord y>
8

    
9
Author:      Cameron Shorter cameron ATshorterDOTnet
10

    
11
Licence:     LGPL as specified in http://www.gnu.org/copyleft/lesser.html .
12

    
13

    
14

    
15
$Id$
16

    
17
$Name$
18

    
19
-->
20

    
21

    
22

    
23
<xsl:stylesheet
24

    
25
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
26

    
27
  xmlns:gml="http://www.opengis.net/gml"
28

    
29
  version="1.0">
30

    
31

    
32

    
33
  <!-- Coordinates template -->
34

    
35
  <xsl:template match="gml:coordinates">
36

    
37

    
38

    
39
    <!-- Convert decimal, coord symbol, tuple symbol to defaults -->
40

    
41
    <xsl:variable name="str" select="translate(.,@decimal,'.')"/>
42

    
43
    <xsl:variable name="str2" select="translate($str,@cs,',')"/>
44

    
45
    <xsl:variable name="str3" select="translate($str2,@ts,' ')"/>
46

    
47
    <xsl:if test="string-length(normalize-space($str3))!=0">
48

    
49
      <xsl:call-template name="parseTuples">
50

    
51
        <xsl:with-param name="str" select="normalize-space($str3)"/>
52

    
53
      </xsl:call-template>
54

    
55
    </xsl:if>
56

    
57
  </xsl:template>
58

    
59

    
60

    
61
  <!-- Print one tuple, then recursively call this template to print remaining tuples -->
62

    
63
  <xsl:template name="parseTuples">
64

    
65
    <xsl:param name="str"/>
66

    
67
    <xsl:param name="cs" select="','"/> <!--symbol to separate coords-->
68

    
69
    <xsl:param name="ts" select="' '"/> <!-- symbol to separate tuples-->
70

    
71
    <xsl:choose>
72

    
73
      <xsl:when test="not(contains($str,$ts))">
74

    
75
        <xsl:call-template name="parseCoords">
76

    
77
          <xsl:with-param name="str" select="$str"/>
78

    
79
          <xsl:with-param name="cs" select="$cs"/>
80

    
81
          <xsl:with-param name="ts" select="$ts"/>
82

    
83
        </xsl:call-template>
84

    
85
      </xsl:when>
86

    
87
      <xsl:otherwise>
88

    
89
        <xsl:call-template name="parseCoords">
90

    
91
          <xsl:with-param name="str" select="substring-before($str,$ts)"/>
92

    
93
          <xsl:with-param name="cs" select="$cs"/>
94

    
95
          <xsl:with-param name="ts" select="$ts"/>
96

    
97
        </xsl:call-template>
98

    
99
        <xsl:call-template name="parseTuples">
100

    
101
          <xsl:with-param name="str" select="substring-after($str,$ts)"/>
102

    
103
          <xsl:with-param name="cs" select="$cs"/>
104

    
105
          <xsl:with-param name="ts" select="$ts"/>
106

    
107
        </xsl:call-template>
108

    
109
      </xsl:otherwise>
110

    
111
    </xsl:choose>
112

    
113
  </xsl:template>
114

    
115

    
116

    
117
  <!-- Extract coords out of a tuple -->
118

    
119
  <xsl:template name="parseCoords">
120

    
121
    <xsl:param name="str"/>
122

    
123
    <xsl:param name="cs"/>
124

    
125

    
126

    
127
    <gml:coord>
128

    
129
      <!-- X coord -->
130

    
131
      <xsl:choose>
132

    
133
        <xsl:when test="not(contains($str,$cs))">
134

    
135
          <xsl:call-template name="printCoord">
136

    
137
            <xsl:with-param name="coord" select="'gml:X'"/>
138

    
139
            <xsl:with-param name="value" select="$str"/>
140

    
141
          </xsl:call-template>
142

    
143
        </xsl:when>
144

    
145
        <xsl:otherwise>
146

    
147
          <xsl:call-template name="printCoord">
148

    
149
            <xsl:with-param name="coord" select="'gml:X'"/>
150

    
151
            <xsl:with-param name="value" select="substring-before($str,$cs)"/>
152

    
153
          </xsl:call-template>
154

    
155
          <!-- Y coord -->
156

    
157
          <xsl:variable name="yz" select="substring-after($str,$cs)"/>
158

    
159
          <xsl:choose>
160

    
161
            <xsl:when test="not(contains($yz,$cs))">
162

    
163
              <xsl:call-template name="printCoord">
164

    
165
                <xsl:with-param name="coord" select="'gml:Y'"/>
166

    
167
                <xsl:with-param name="value" select="$yz"/>
168

    
169
              </xsl:call-template>
170

    
171
            </xsl:when>
172

    
173
            <xsl:otherwise>
174

    
175
              <xsl:call-template name="printCoord">
176

    
177
                <xsl:with-param name="coord" select="'gml:Y'"/>
178

    
179
                <xsl:with-param name="value" select="substring-before($yz,$cs)"/>
180

    
181
              </xsl:call-template>
182

    
183
              <!-- Z coord -->
184

    
185
              <xsl:call-template name="printCoord">
186

    
187
                <xsl:with-param name="coord" select="'gml:Z'"/>
188

    
189
                <xsl:with-param name="value" select="substring-after($yz,$cs)"/>
190

    
191
              </xsl:call-template>
192

    
193
            </xsl:otherwise>
194

    
195
          </xsl:choose>
196

    
197
        </xsl:otherwise>
198

    
199
      </xsl:choose>
200

    
201
    </gml:coord>
202

    
203
  </xsl:template>
204

    
205

    
206

    
207
  <!-- Print X, Y or Z coord: <X>123</X> -->
208

    
209
  <xsl:template name="printCoord">
210

    
211
    <xsl:param name="coord"/>
212

    
213
    <xsl:param name="value"/>
214

    
215
    <xsl:element name="{$coord}">
216

    
217
      <xsl:value-of select="$value"/>
218

    
219
    </xsl:element>
220

    
221
  </xsl:template>
222

    
223

    
224

    
225
  <!-- All other nodes are copied -->
226

    
227
  <xsl:template match="*|@*|comment()|processing-instruction()|text()">
228

    
229
    <xsl:copy>
230

    
231
      <xsl:apply-templates
232

    
233
       select="*|@*|comment()|processing-instruction()|text()"/>
234

    
235
    </xsl:copy>
236

    
237
  </xsl:template>
238

    
239

    
240

    
241
</xsl:stylesheet>
242

    
(38-38/111)