source: subversion/applications/utils/export/osmgarminmap/mpx2mp.xsl @ 28719

Last change on this file since 28719 was 4488, checked in by jochen, 12 years ago

Delete zero length segments from polylines with mpl2mp.pl script
Added Ids to generated files for debugging

File size: 5.2 KB
Line 
1<?xml version='1.0' encoding='iso-8859-1' ?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 
4<!--
5
6Copyright (C) 2006  Jochen Topf <jochen@remote.org>
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
21
22-->
23
24        <xsl:output method="text" encoding="iso-8859-1"/>
25
26        <xsl:key name='point' match='/defs/point/feature' use="concat(@type,'=',@subtype)"/>
27        <xsl:key name='city' match='/defs/city/feature' use="concat(@type,'=',@subtype)"/>
28        <xsl:key name='polyline' match="/defs/polyline/feature" use='@type'/>
29        <xsl:key name='polygon' match='/defs/polygon/feature' use='@type'/>
30        <xsl:key name='feature' match='/defs/*' use='name()'/>
31
32        <xsl:variable name='data' select='document(/defs/@data)/map'/>
33
34    <xsl:template match="/defs">
35        <xsl:text>[IMG ID]
36ID=</xsl:text>
37        <xsl:value-of select="$data/@mapid"/>
38        <xsl:text>
39Name=</xsl:text>
40        <xsl:value-of select="$data/@name"/>
41        <xsl:text>
42TreSize=5000
43RgnLimit=1024
44Transparent=Y
45LBLcoding=9
46Codepage=1252
47Levels=8
48Level0=24
49Level1=23
50Level2=22
51Level3=21
52Level4=20
53Level5=19
54Level6=18
55Level7=17
56Zoom0=0
57Zoom1=1
58Zoom2=2
59Zoom3=3
60Zoom4=4
61Zoom5=5
62Zoom6=6
63Zoom7=7
64Transparent=N
65Elevation=m
66[END-IMG ID]
67
68</xsl:text>
69
70        <xsl:apply-templates select="$data/point|$data/city|$data/polyline|$data/polygon" mode="data">
71            <xsl:with-param name="mapping" select="/defs"/>
72        </xsl:apply-templates>
73    </xsl:template>
74
75    <xsl:template match="point|city" mode="data">
76        <xsl:param name="mapping"/>
77        <xsl:variable name="current" select="name(.)"/>
78        <xsl:variable name="feature-id">
79            <xsl:for-each select="$mapping">
80                <xsl:value-of select="key('feature', $current)/@id"/>
81            </xsl:for-each>
82        </xsl:variable>
83
84        <xsl:variable name="type" select="concat(@type,'=',@subtype)"/>
85       
86        <xsl:text>[</xsl:text>
87        <xsl:value-of select="$feature-id"/>
88        <xsl:text>]
89; id=</xsl:text>
90        <xsl:value-of select="@id"/>
91        <xsl:text>
92Type=</xsl:text>
93        <xsl:for-each select="$mapping">
94            <xsl:value-of select="key($current, $type)/@garmin_id"/>
95        </xsl:for-each>
96
97        <xsl:text>
98SubType=</xsl:text>
99        <xsl:for-each select="$mapping">
100            <xsl:value-of select="key($current, $type)/@garmin_subid"/>
101        </xsl:for-each>
102
103        <xsl:if test="@endlevel!=''">
104            <xsl:text>
105EndLevel=</xsl:text>
106            <xsl:value-of select="@endlevel"/>
107        </xsl:if>
108
109        <xsl:if test="label">
110            <xsl:text>
111Label=</xsl:text>
112            <xsl:value-of select="translate(label, 'abcdefghijklmnopqrstuvwxyzöüä', 'ABCDEFGHIJKLMNOPQRSTUVWXYZÖÜÄ')"/>
113        </xsl:if>
114
115        <xsl:text>
116Data0=(</xsl:text>
117        <xsl:value-of select="data/@latlon"/>
118        <xsl:text>)
119[END-</xsl:text>
120        <xsl:value-of select="$feature-id"/>
121        <xsl:text>]
122
123</xsl:text>
124
125    </xsl:template>
126
127    <xsl:template match="polyline|polygon" mode="data">
128        <xsl:param name="mapping"/>
129        <xsl:variable name="current" select="name(.)"/>
130        <xsl:variable name="feature-id">
131            <xsl:for-each select="$mapping">
132                <xsl:value-of select="key('feature', $current)/@id"/>
133            </xsl:for-each>
134        </xsl:variable>
135
136        <xsl:text>[</xsl:text>
137        <xsl:value-of select="$feature-id"/>
138        <xsl:text>]
139; id=</xsl:text>
140        <xsl:value-of select="@id"/>
141        <xsl:text>
142Type=</xsl:text>
143        <xsl:variable name="type" select="@type"/>
144        <xsl:for-each select="$mapping">
145            <xsl:value-of select="key($current, $type)/@garmin_id"/>
146        </xsl:for-each>
147
148        <xsl:if test="@endlevel!=''">
149            <xsl:text>
150EndLevel=</xsl:text>
151            <xsl:value-of select="@endlevel"/>
152        </xsl:if>
153
154        <xsl:if test="label">
155            <xsl:text>
156Label=</xsl:text>
157            <xsl:value-of select="translate(label, 'abcdefghijklmnopqrstuvwxyzöüä', 'ABCDEFGHIJKLMNOPQRSTUVWXYZÖÜÄ')"/>
158        </xsl:if>
159
160        <xsl:text>
161Data0=</xsl:text>
162        <xsl:apply-templates select="data[@level=0]" mode="data"/>
163        <xsl:text>
164[END-</xsl:text>
165        <xsl:value-of select="$feature-id"/>
166        <xsl:text>]
167
168</xsl:text>
169
170    </xsl:template>
171
172    <xsl:template match="data" mode="data">
173        <xsl:for-each select="segment">
174            <xsl:if test="position()!=1">
175                <xsl:text>,</xsl:text> 
176            </xsl:if>
177            <xsl:text>(</xsl:text> 
178            <xsl:value-of select="@from"/>
179            <xsl:text>),(</xsl:text> 
180            <xsl:value-of select="@to"/>
181            <xsl:text>)</xsl:text> 
182        </xsl:for-each>
183    </xsl:template>
184
185</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.