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