|
1 <?xml version="1.0"?> |
|
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
|
3 <!--Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 All rights reserved. |
|
5 This component and the accompanying materials are made available |
|
6 under the terms of the License "Eclipse Public License v1.0" |
|
7 which accompanies this distribution, and is available |
|
8 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
|
10 Initial Contributors: |
|
11 Nokia Corporation - initial contribution. |
|
12 Contributors: |
|
13 Description: |
|
14 Downgrade a 3.x system definition into the 2.0.1 syntax |
|
15 --> |
|
16 <xsl:output method="xml" indent="yes"/> |
|
17 |
|
18 <xsl:param name="Path">os/deviceplatformrelease/foundation_system/system_model</xsl:param> |
|
19 <!-- $Path is the location of the root system definition XML file. Must not end in / |
|
20 This is used to compute the absolute paths the 2.0 syntax needs--> |
|
21 <xsl:param name="Root"/> <!-- space separated list of root variables in the form "VAR1=value1 VAR=value2" --> |
|
22 <xsl:variable name="root" select="concat(' ',$Root,' ')"/> <!-- sort of hack to allow absolute paths in downgraded output --> |
|
23 <xsl:variable name="srcroot" select="substring-before(substring-after($root,' SRCROOT='),' ')"/> <!-- the default path prefix --> |
|
24 |
|
25 <xsl:template match="/*"> |
|
26 <xsl:message terminate="yes">ERROR: Cannot process this document</xsl:message> |
|
27 </xsl:template> |
|
28 |
|
29 <!-- can only handle 3.0.0 to 2.0.1 transforms |
|
30 Assumes only packages are using href |
|
31 --> |
|
32 <xsl:template match="/SystemDefinition[@schema='3.0.0']"> |
|
33 <!-- process root system definition or package definition--> |
|
34 <xsl:call-template name="DTD"/> <!-- insert 2.0.01 DTD --> |
|
35 <SystemDefinition name="{*/@name}" schema="2.0.1"> |
|
36 <xsl:apply-templates select="*|comment()"/> |
|
37 </SystemDefinition> |
|
38 </xsl:template> |
|
39 |
|
40 <xsl:template match="/SystemDefinition[@schema='3.0.0' and systemModel]"> |
|
41 <xsl:call-template name="DTD"/> <!-- insert 2.0.01 DTD --> |
|
42 <SystemDefinition name="{systemModel/@name}" schema="2.0.1"> |
|
43 <xsl:apply-templates select="*|comment()"/> |
|
44 </SystemDefinition> |
|
45 </xsl:template> |
|
46 |
|
47 <xsl:template match="/SystemDefinition/package[@href]" priority="2"> |
|
48 <xsl:message terminate="yes">ERROR: Package definition (<xsl:value-of select="@id"/>) cannot link another package</xsl:message> |
|
49 </xsl:template> |
|
50 |
|
51 <xsl:template match="/SystemDefinition/package" priority="1"> |
|
52 <!-- process package definition file--> |
|
53 <systemModel> |
|
54 <layer name="anonymous"> <!-- fake layer --> |
|
55 <block> |
|
56 <xsl:apply-templates mode="copy" select="@id|@name|@span|@level|@levels"/><!-- valid attribuites for 2.0 --> |
|
57 <xsl:apply-templates select="*|comment()"> |
|
58 <xsl:with-param name="path" select="concat($Path,'/')"/> <!-- need to keep tack of where the current document is --> |
|
59 </xsl:apply-templates> |
|
60 </block> |
|
61 </layer> |
|
62 </systemModel> |
|
63 </xsl:template> |
|
64 |
|
65 |
|
66 |
|
67 <xsl:template match="/"><xsl:apply-templates select="*"/></xsl:template> |
|
68 <xsl:template match="@*|comment()"><xsl:copy-of select="."/></xsl:template> |
|
69 <!-- comments are copied verbatim. Attribtues are copied by default --> |
|
70 |
|
71 <xsl:template match="systemModel"> |
|
72 <systemModel> |
|
73 <xsl:apply-templates select="*|comment()"> <!-- no attributes --> |
|
74 <xsl:with-param name="path" select="$Path"/> <!-- need to keep tack of where the current document is --> |
|
75 </xsl:apply-templates> |
|
76 </systemModel> |
|
77 </xsl:template> |
|
78 |
|
79 <xsl:template mode="copy" match="@*"> |
|
80 <xsl:copy-of select="."/> |
|
81 </xsl:template> |
|
82 |
|
83 <xsl:template mode="copy" match="@id"> <!-- id in 3.0 is name in 2.0 --> |
|
84 <xsl:attribute name="name"><xsl:value-of select="."/></xsl:attribute> |
|
85 </xsl:template> |
|
86 |
|
87 <xsl:template mode="copy" match="@name"> <!-- name in 3.0 is long-name in 2.0.1 --> |
|
88 <xsl:if test=".!=../@id"> <!-- don't bother if it will be the same as name --> |
|
89 <xsl:attribute name="long-name"><xsl:value-of select="."/></xsl:attribute> |
|
90 </xsl:if> |
|
91 </xsl:template> |
|
92 |
|
93 <xsl:template match="layer"><xsl:param name="path"/> |
|
94 <layer> |
|
95 <xsl:apply-templates mode="copy" select="@id|@name|@span|@levels"/> <!-- valid attribuites for 2.0 --> |
|
96 <xsl:apply-templates select="*|comment()"> |
|
97 <xsl:with-param name="path" select="$path"/> |
|
98 </xsl:apply-templates> |
|
99 </layer> |
|
100 </xsl:template> |
|
101 |
|
102 <xsl:template match="layer/package"><!-- translates to block --> |
|
103 <xsl:param name="path"/> |
|
104 <block> |
|
105 <xsl:apply-templates mode="copy" select="@id|@name|@span|@level|@levels"/><!-- valid attribuites for 2.0 --> |
|
106 <xsl:choose> |
|
107 <xsl:when test="@href"> |
|
108 <xsl:variable name="this" select="."/> |
|
109 <xsl:variable name="prefixmap" select="ancestor::SystemDefinition/*/meta[@rel='link-mapping']/map-prefix[starts-with(current()/@href,@link)]"/> |
|
110 <xsl:for-each select="document(@href,.)/SystemDefinition/*"> |
|
111 <xsl:variable name="my-id"><xsl:apply-templates mode="normalize-id" select="@id"/></xsl:variable> |
|
112 <xsl:variable name="other-id"><xsl:apply-templates mode="normalize-id" select="$this/@id"/></xsl:variable> |
|
113 <xsl:if test="$my-id != $other-id"> |
|
114 <xsl:message terminate="yes">ERROR: Package IDs do not match: <xsl:value-of select="$my-id"/> vs <xsl:value-of select="$other-id"/></xsl:message> |
|
115 </xsl:if> |
|
116 <xsl:if test="@name and @name!=@id and not($this/@name and $this/@name=$this/@id)"> |
|
117 <!-- set long-name only if name is different from the id and not set in child doc --> |
|
118 <xsl:attribute name="long-name"><xsl:value-of select="@name"/></xsl:attribute> |
|
119 </xsl:if> |
|
120 <xsl:for-each select="@span|@levels|@level"> |
|
121 <!-- copy only if not set in child doc --> |
|
122 <xsl:if test="not(this/@*[name()=name(current())])"> |
|
123 <xsl:copy-of select="."/> |
|
124 </xsl:if> |
|
125 </xsl:for-each> |
|
126 <xsl:apply-templates select="*|comment()"> |
|
127 <xsl:with-param name="path"> |
|
128 <xsl:choose> |
|
129 <xsl:when test="$prefixmap"> |
|
130 <xsl:call-template name="normpath"> |
|
131 <xsl:with-param name="path"> |
|
132 <xsl:apply-templates select="$prefixmap/@to"/> |
|
133 <xsl:value-of select="substring-after($this/@href,$prefixmap/@link)"/> |
|
134 </xsl:with-param> |
|
135 </xsl:call-template> |
|
136 </xsl:when> |
|
137 <xsl:when test="starts-with($this/@href,'/')"> <!-- absolute path --> |
|
138 <xsl:call-template name="normpath"> |
|
139 <xsl:with-param name="path" select="$this/@href"/> |
|
140 </xsl:call-template> |
|
141 </xsl:when> |
|
142 <xsl:when test="contains($this/@href,'://')"> <!-- generic URI --> |
|
143 <xsl:call-template name="normpath"> |
|
144 <xsl:with-param name="path" select="substring-after($this/@href,'://')"/> |
|
145 </xsl:call-template> |
|
146 </xsl:when> |
|
147 <xsl:otherwise> |
|
148 <xsl:call-template name="normpath"> |
|
149 <xsl:with-param name="path" select="concat($path,'/',$this/@href)"/> |
|
150 </xsl:call-template> |
|
151 </xsl:otherwise> |
|
152 </xsl:choose> |
|
153 </xsl:with-param> |
|
154 </xsl:apply-templates> |
|
155 </xsl:for-each> |
|
156 </xsl:when> |
|
157 <xsl:otherwise> |
|
158 <xsl:apply-templates select="*|comment()"> |
|
159 <xsl:with-param name="path" select="$path"/> |
|
160 </xsl:apply-templates> |
|
161 </xsl:otherwise> |
|
162 </xsl:choose> |
|
163 </block> |
|
164 </xsl:template> |
|
165 |
|
166 <xsl:template match="package/package"> <!-- translates to subblock --><xsl:param name="path"/> |
|
167 <subblock> |
|
168 <xsl:apply-templates mode="copy" select="@id|@name"/> |
|
169 <xsl:apply-templates select="*|comment()"> |
|
170 <xsl:with-param name="path" select="$path"/> |
|
171 </xsl:apply-templates> |
|
172 </subblock> |
|
173 </xsl:template> |
|
174 |
|
175 <xsl:template match="package/package/pacakge"> <!-- cannot nest this deep --><xsl:param name="path"/> |
|
176 <xsl:message>WARNING: Excessive nesting of packages: Ignoring <xsl:value-of select="@id"/></xsl:message> |
|
177 <xsl:apply-templates select="*|comment()"> |
|
178 <xsl:with-param name="path" select="$path"/> |
|
179 </xsl:apply-templates> |
|
180 </xsl:template> |
|
181 |
|
182 |
|
183 <xsl:template match="collection"><xsl:param name="path"/> |
|
184 <collection> |
|
185 <xsl:apply-templates mode="copy" select="@id|@name|@level"/> |
|
186 <xsl:apply-templates select="*|comment()"> |
|
187 <xsl:with-param name="path" select="$path"/> |
|
188 </xsl:apply-templates> |
|
189 </collection> |
|
190 </xsl:template> |
|
191 |
|
192 |
|
193 <xsl:template match="component"><xsl:param name="path"/> |
|
194 <component> |
|
195 <xsl:apply-templates mode="copy" select="@id|@name|@deprecated|@introduced|@filter|@purpose"/> |
|
196 <xsl:if test="contains(concat(' ',@class,' '),' plugin ')"> |
|
197 <xsl:attribute name="plugin">Y</xsl:attribute> |
|
198 </xsl:if> |
|
199 <xsl:call-template name="class"> |
|
200 <xsl:with-param name="remove">plugin</xsl:with-param> |
|
201 <xsl:with-param name="add"> |
|
202 <xsl:if test="not(*) and comment()">placeholder</xsl:if> |
|
203 <xsl:if test="@target='desktop'"> PC</xsl:if> |
|
204 </xsl:with-param> |
|
205 </xsl:call-template> |
|
206 <xsl:apply-templates select="*|comment()"> |
|
207 <xsl:with-param name="path" select="$path"/> |
|
208 </xsl:apply-templates> |
|
209 </component> |
|
210 </xsl:template> |
|
211 |
|
212 <xsl:template match="unit[@base and not(@mrp or @bldFile)]"/> |
|
213 |
|
214 <xsl:template match="unit"><xsl:param name="path"/> |
|
215 <unit> |
|
216 <xsl:apply-templates select="@mrp|@bldFile|@late"> |
|
217 <xsl:with-param name="path" select="$path"/> |
|
218 </xsl:apply-templates> |
|
219 <xsl:copy-of select="@filter|@root[not(contains($root,concat(' ',.,'=')))]|@version|@prebuilt|@priority"/> |
|
220 </unit> |
|
221 </xsl:template> |
|
222 |
|
223 <xsl:template match="unit/@late"> <!-- 2.0 uses Y/N, 3.0 uses yes/no --> |
|
224 <xsl:attribute name="{name()}"> |
|
225 <xsl:choose> |
|
226 <xsl:when test=".='yes'">Y</xsl:when> |
|
227 <xsl:when test=".='no'">N</xsl:when> |
|
228 </xsl:choose> |
|
229 </xsl:attribute> |
|
230 </xsl:template> |
|
231 |
|
232 <xsl:template match="@mrp|@bldFile"><xsl:param name="path"/> |
|
233 <xsl:attribute name="{name()}"> |
|
234 <xsl:choose> |
|
235 <xsl:when test="../@root"> |
|
236 <xsl:variable name="pre" select="substring-before(substring-after($root,concat(' ',../@root,'=')),' ')"/> |
|
237 <xsl:value-of select="$pre"/> |
|
238 <xsl:if test="$pre!='' and $pre!='/'">/</xsl:if> |
|
239 </xsl:when> |
|
240 <xsl:when test="$srcroot='/'"> <!-- treat all paths as absolute --> |
|
241 <xsl:value-of select="$srcroot"/> |
|
242 </xsl:when> |
|
243 <xsl:when test="$srcroot!=''"> |
|
244 <xsl:value-of select="concat($srcroot,'/')"/> |
|
245 </xsl:when> |
|
246 </xsl:choose> |
|
247 <xsl:choose> |
|
248 <xsl:when test="starts-with(.,'/')"> <!-- keep absolute paths verbatim (barring the leading / ) --> |
|
249 <xsl:value-of select="substring-after(.,'/')"/> |
|
250 </xsl:when> |
|
251 <xsl:otherwise> |
|
252 <xsl:call-template name="normpath"> |
|
253 <xsl:with-param name="path"> |
|
254 <xsl:call-template name="before"> |
|
255 <xsl:with-param name="text" select="$path"/> |
|
256 </xsl:call-template> |
|
257 <xsl:value-of select="."/> |
|
258 </xsl:with-param> |
|
259 </xsl:call-template> |
|
260 </xsl:otherwise> |
|
261 </xsl:choose> |
|
262 </xsl:attribute> |
|
263 </xsl:template> |
|
264 |
|
265 <xsl:template match="meta"/> <!-- strip all meta tags --> |
|
266 |
|
267 <xsl:template match="meta[info/@contract]"> <!-- except contract --> |
|
268 <xsl:copy-of select="info/@contract"/> |
|
269 </xsl:template> |
|
270 |
|
271 |
|
272 <xsl:template match="meta[@rel='link-mapping']/map-prefix/@to"> |
|
273 <xsl:choose> |
|
274 <xsl:when test="starts-with(.,'/')"><xsl:value-of select="substring(.,2)"/></xsl:when> <!-- absolute paths in 3.0 are relative in 2.0 --> |
|
275 <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise> |
|
276 </xsl:choose> |
|
277 </xsl:template> |
|
278 |
|
279 |
|
280 <xsl:template match="@id" mode="normalize-id"> |
|
281 <xsl:choose> |
|
282 <xsl:when test="contains(@id,':')"><xsl:value-of select="substring-after(@id,':')"/></xsl:when> |
|
283 <xsl:otherwise><xsl:value-of select="@id"/></xsl:otherwise> |
|
284 </xsl:choose> |
|
285 </xsl:template> |
|
286 |
|
287 <xsl:template name="class"><xsl:param name="remove"/><xsl:param name="add"/> |
|
288 <!-- returns the value of the class attribute with the space-separated list of names in $remove taken out and those in $add added on (does not check for duplicates) --> |
|
289 <xsl:param name="class" select="normalize-space(@class)"/> |
|
290 <xsl:variable name="r"> |
|
291 <xsl:text> </xsl:text> |
|
292 <xsl:choose> |
|
293 <xsl:when test="contains($remove,' ')"><xsl:value-of select="substring-before($remove,' ')"/></xsl:when> |
|
294 <xsl:otherwise><xsl:value-of select="$remove"/></xsl:otherwise> |
|
295 </xsl:choose> |
|
296 <xsl:text> </xsl:text> |
|
297 </xsl:variable> |
|
298 <xsl:variable name="c"> |
|
299 <xsl:choose> |
|
300 <xsl:when test="contains(concat(' ',$class,' '),$r)"> |
|
301 <xsl:value-of select="substring-before(concat(' ',$class,' '),$r)"/> |
|
302 <xsl:text> </xsl:text> |
|
303 <xsl:value-of select="substring-after(concat(' ',$class,' '),$r)"/> |
|
304 </xsl:when> |
|
305 <xsl:otherwise><xsl:value-of select="$class"/></xsl:otherwise> |
|
306 </xsl:choose> |
|
307 <xsl:if test="normalize-space($add)!=''"><xsl:value-of select="concat(' ',normalize-space($add))"/></xsl:if> |
|
308 </xsl:variable> |
|
309 <xsl:choose> |
|
310 <xsl:when test="contains($remove,' ')"> |
|
311 <xsl:call-template name="class"> |
|
312 <xsl:with-param name="remove" select="substring-after($remove,' ')"/> |
|
313 <xsl:with-param name="class" select="$c"/> |
|
314 </xsl:call-template> |
|
315 </xsl:when> |
|
316 <xsl:when test="normalize-space($c)!=''"> |
|
317 <xsl:attribute name="class"> |
|
318 <xsl:value-of select="normalize-space($c)"/> |
|
319 </xsl:attribute> |
|
320 </xsl:when> |
|
321 </xsl:choose> |
|
322 </xsl:template> |
|
323 |
|
324 <xsl:template name="normpath"><xsl:param name="path"/> |
|
325 <!-- normalize out any ".." in the path in $path --> |
|
326 <xsl:choose> |
|
327 <xsl:when test="contains($path,'/../')"> |
|
328 <xsl:call-template name="normpath"> |
|
329 <xsl:with-param name="path"> |
|
330 <xsl:call-template name="before"> |
|
331 <xsl:with-param name="text" select="substring-before($path,'/../')"/> |
|
332 </xsl:call-template> |
|
333 <xsl:value-of select="substring-after($path,'/../')"/> |
|
334 </xsl:with-param> |
|
335 </xsl:call-template> |
|
336 </xsl:when> |
|
337 <xsl:otherwise><xsl:value-of select="$path"/></xsl:otherwise> |
|
338 </xsl:choose> |
|
339 </xsl:template> |
|
340 |
|
341 <!-- return all text before the last / --> |
|
342 <xsl:template name="before"><xsl:param name="text"/> |
|
343 <xsl:if test="contains($text,'/')"> |
|
344 <xsl:value-of select="substring-before($text,'/')"/>/<xsl:call-template name="before"><xsl:with-param name="text" select="substring-after($text,'/')"/></xsl:call-template> |
|
345 </xsl:if> |
|
346 </xsl:template> |
|
347 |
|
348 <xsl:template name="DTD"> |
|
349 <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE SystemDefinition [ |
|
350 <!ELEMENT SystemDefinition ( systemModel )> |
|
351 <!ATTLIST SystemDefinition |
|
352 name CDATA #REQUIRED |
|
353 schema CDATA #REQUIRED |
|
354 > |
|
355 <!-- all paths are relative to the environment variable specified by the root attribute, or SOURCEROOT if not. --> |
|
356 |
|
357 <!-- System Model Section of DTD --> |
|
358 <!ELEMENT systemModel (layer+)> |
|
359 |
|
360 <!ELEMENT layer (block* | collection*)*> |
|
361 <!-- Kernel Services, Base Services, OS Services, Etc --> |
|
362 <!ATTLIST layer |
|
363 name CDATA #REQUIRED |
|
364 long-name CDATA #IMPLIED |
|
365 levels NMTOKENS #IMPLIED |
|
366 span CDATA #IMPLIED |
|
367 > |
|
368 |
|
369 <!ELEMENT block (subblock* | collection*)*> |
|
370 <!-- Generic OS services, Comms Services, etc --> |
|
371 <!ATTLIST block |
|
372 levels NMTOKENS #IMPLIED |
|
373 span CDATA #IMPLIED |
|
374 level NMTOKEN #IMPLIED |
|
375 name CDATA #REQUIRED |
|
376 long-name CDATA #IMPLIED |
|
377 > |
|
378 |
|
379 <!ELEMENT subblock (collection)*> |
|
380 <!-- Cellular Baseband Services, Networking Services, etc --> |
|
381 <!ATTLIST subblock |
|
382 name CDATA #REQUIRED |
|
383 long-name CDATA #IMPLIED |
|
384 > |
|
385 |
|
386 <!ELEMENT collection (component)*> |
|
387 <!-- Screen Driver, Content Handling, etc --> |
|
388 <!ATTLIST collection |
|
389 name CDATA #REQUIRED |
|
390 long-name CDATA #IMPLIED |
|
391 level NMTOKEN #IMPLIED |
|
392 > |
|
393 |
|
394 <!ELEMENT component (unit)*> |
|
395 <!-- contains units or is a package or prebuilt --> |
|
396 <!ATTLIST component |
|
397 name CDATA #REQUIRED |
|
398 long-name CDATA #IMPLIED |
|
399 deprecated CDATA #IMPLIED |
|
400 introduced CDATA #IMPLIED |
|
401 contract CDATA #IMPLIED |
|
402 plugin (Y|N) "N" |
|
403 filter CDATA #IMPLIED |
|
404 class NMTOKENS #IMPLIED |
|
405 supports CDATA #IMPLIED |
|
406 purpose ( optional | mandatory | development ) "optional" |
|
407 > |
|
408 |
|
409 <!ELEMENT unit EMPTY > |
|
410 <!-- must be buildable (bld.inf) --> |
|
411 <!-- bldFile may someday be removed in favour of mrp --> |
|
412 <!ATTLIST unit |
|
413 mrp CDATA #IMPLIED |
|
414 filter CDATA #IMPLIED |
|
415 bldFile CDATA #IMPLIED |
|
416 root CDATA #IMPLIED |
|
417 version NMTOKEN #IMPLIED |
|
418 prebuilt NMTOKEN #IMPLIED |
|
419 late (Y|N) #IMPLIED |
|
420 priority CDATA #IMPLIED |
|
421 > |
|
422 ]> |
|
423 ]]></xsl:text> |
|
424 </xsl:template> |
|
425 </xsl:stylesheet> |