bldsystemtools/sysdeftools/sysdefdowngrade.xsl
changeset 0 83f4b4db085c
child 18 99082257a271
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     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:for-each select="document(@href,.)/SystemDefinition/*">
       
   110 					<xsl:variable name="my-id"><xsl:apply-templates mode="normalize-id" select="@id"/></xsl:variable>
       
   111 					<xsl:variable name="other-id"><xsl:apply-templates mode="normalize-id" select="$this/@id"/></xsl:variable>
       
   112 					<xsl:if test="$my-id != $other-id">
       
   113 						<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>
       
   114 					</xsl:if>
       
   115 					<xsl:if test="@name and @name!=@id and not($this/@name and $this/@name=$this/@id)">
       
   116 						<!-- set long-name only if name is different from the id and not set in child doc -->
       
   117 						<xsl:attribute name="long-name"><xsl:value-of select="@name"/></xsl:attribute>
       
   118 					</xsl:if>						
       
   119 					<xsl:for-each select="@span|@levels|@level">
       
   120 						<!-- copy only if not set in child doc -->
       
   121 						<xsl:if test="not(this/@*[name()=name(current())])">
       
   122 							<xsl:copy-of select="."/>
       
   123 						</xsl:if>
       
   124 					</xsl:for-each>
       
   125 					<xsl:apply-templates select="*|comment()">
       
   126 	  					<xsl:with-param name="path">
       
   127 	  						<xsl:call-template name="normpath">
       
   128 	  							<xsl:with-param name="path" select="concat($path,'/',$this/@href)"/>
       
   129 	  						</xsl:call-template>
       
   130 	  					</xsl:with-param> 
       
   131 	  				</xsl:apply-templates>
       
   132 				</xsl:for-each>
       
   133 			</xsl:when>
       
   134 			<xsl:otherwise>
       
   135 				<xsl:apply-templates select="*|comment()">
       
   136   					<xsl:with-param name="path" select="$path"/> 
       
   137   				</xsl:apply-templates>
       
   138 			</xsl:otherwise>
       
   139 		</xsl:choose>
       
   140 	</block>
       
   141 </xsl:template>
       
   142 
       
   143 <xsl:template match="package/package">	<!-- translates to subblock --><xsl:param name="path"/>
       
   144 	<subblock>
       
   145 		<xsl:apply-templates mode="copy" select="@id|@name"/>
       
   146 		<xsl:apply-templates select="*|comment()">
       
   147 			<xsl:with-param name="path" select="$path"/> 
       
   148 		</xsl:apply-templates>
       
   149 	</subblock>
       
   150 </xsl:template>
       
   151 
       
   152 <xsl:template match="package/package/pacakge"> <!-- cannot nest this deep --><xsl:param name="path"/>
       
   153 	<xsl:message>WARNING: Excessive nesting of packages: Ignoring <xsl:value-of select="@id"/></xsl:message>
       
   154 	<xsl:apply-templates select="*|comment()">
       
   155 		<xsl:with-param name="path" select="$path"/> 
       
   156 	</xsl:apply-templates>
       
   157 </xsl:template>
       
   158 
       
   159 
       
   160 <xsl:template match="collection"><xsl:param name="path"/>
       
   161 	<collection>
       
   162 		<xsl:apply-templates mode="copy" select="@id|@name|@level"/>
       
   163 		<xsl:apply-templates select="*|comment()">
       
   164 			<xsl:with-param name="path" select="$path"/> 
       
   165 		</xsl:apply-templates>
       
   166 	</collection>
       
   167 </xsl:template>
       
   168 
       
   169 
       
   170 <xsl:template match="component"><xsl:param name="path"/>
       
   171 	<component>
       
   172 		<xsl:apply-templates mode="copy" select="@id|@name|@deprecated|@introduced|@filter|@purpose"/>
       
   173 		<xsl:if test="contains(concat(' ',@class,' '),' plugin ')">
       
   174 			<xsl:attribute name="plugin">Y</xsl:attribute>
       
   175 		</xsl:if>
       
   176 		<xsl:call-template name="class">
       
   177 			<xsl:with-param name="remove">plugin</xsl:with-param>
       
   178 			<xsl:with-param name="add">
       
   179 				<xsl:if test="not(*) and comment()">placeholder</xsl:if>
       
   180 				<xsl:if test="@target='desktop'"> PC</xsl:if>
       
   181 			</xsl:with-param>
       
   182 		</xsl:call-template>
       
   183 	  	<xsl:apply-templates select="*|comment()">
       
   184 			<xsl:with-param name="path" select="$path"/> 
       
   185 		</xsl:apply-templates>
       
   186 	</component>
       
   187 </xsl:template>
       
   188 
       
   189 <xsl:template match="unit[@base and not(@mrp or @bldFile)]"/>
       
   190 
       
   191 <xsl:template match="unit"><xsl:param name="path"/>
       
   192 	<unit>
       
   193 		<xsl:apply-templates select="@mrp|@bldFile|@late">
       
   194 			<xsl:with-param name="path" select="$path"/> 
       
   195 		</xsl:apply-templates>
       
   196 		<xsl:copy-of select="@filter|@root[not(contains($root,concat(' ',.,'=')))]|@version|@prebuilt|@priority"/>
       
   197 	</unit>
       
   198 </xsl:template>
       
   199 
       
   200 <xsl:template match="unit/@late"> <!-- 2.0 uses Y/N, 3.0 uses yes/no -->
       
   201 	<xsl:attribute name="{name()}">
       
   202 		<xsl:choose>
       
   203 			<xsl:when test=".='yes'">Y</xsl:when>
       
   204 			<xsl:when test=".='no'">N</xsl:when>
       
   205 		</xsl:choose>
       
   206 	</xsl:attribute>
       
   207 </xsl:template>
       
   208 
       
   209 <xsl:template match="@mrp|@bldFile"><xsl:param name="path"/>
       
   210 	<xsl:attribute name="{name()}">
       
   211 		<xsl:choose>
       
   212 			<xsl:when test="../@root">
       
   213 				<xsl:variable name="pre" select="substring-before(substring-after($root,concat(' ',../@root,'=')),' ')"/>
       
   214 				<xsl:if test="$pre!=''"><xsl:value-of select="concat($pre,'/')"/></xsl:if>
       
   215 			</xsl:when>
       
   216 			<xsl:when test="$srcroot!=''">
       
   217 				<xsl:value-of select="concat($srcroot,'/')"/>
       
   218 			</xsl:when>
       
   219 		</xsl:choose>
       
   220 		<xsl:choose>
       
   221 		<xsl:when test="starts-with(.,'/')"> <!-- keep absolute paths verbatim (barring the leading / ) -->
       
   222 			<xsl:value-of select="substring-after(.,'/')"/>
       
   223 		</xsl:when>
       
   224 		<xsl:otherwise>	
       
   225 			<xsl:call-template name="normpath">
       
   226   				<xsl:with-param name="path">
       
   227   					<xsl:call-template name="before">
       
   228 						<xsl:with-param name="text" select="$path"/>
       
   229 					</xsl:call-template>
       
   230 					<xsl:value-of select="."/>
       
   231   				</xsl:with-param>
       
   232   			</xsl:call-template>
       
   233 		</xsl:otherwise>
       
   234 	</xsl:choose>
       
   235 	</xsl:attribute>
       
   236 </xsl:template>
       
   237 
       
   238 <xsl:template match="meta"/> <!-- strip all meta tags -->
       
   239 
       
   240 <xsl:template match="meta[info/@contract]"> <!-- except contract -->
       
   241 	<xsl:copy-of select="info/@contract"/>
       
   242 </xsl:template>
       
   243 
       
   244 <xsl:template match="@id" mode="normalize-id">
       
   245 	<xsl:choose>
       
   246 		<xsl:when test="contains(@id,':')"><xsl:value-of select="substring-after(@id,':')"/></xsl:when>
       
   247 		<xsl:otherwise><xsl:value-of select="@id"/></xsl:otherwise>
       
   248 	</xsl:choose>
       
   249 </xsl:template>
       
   250 
       
   251 <xsl:template name="class"><xsl:param name="remove"/><xsl:param name="add"/>
       
   252 <!--  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) -->
       
   253 	<xsl:param name="class" select="normalize-space(@class)"/>
       
   254 	<xsl:variable name="r">
       
   255 		<xsl:text> </xsl:text>
       
   256 		<xsl:choose>
       
   257 			<xsl:when test="contains($remove,' ')"><xsl:value-of select="substring-before($remove,' ')"/></xsl:when>
       
   258 			<xsl:otherwise><xsl:value-of select="$remove"/></xsl:otherwise>
       
   259 		</xsl:choose>
       
   260 		<xsl:text> </xsl:text>
       
   261 	</xsl:variable>
       
   262 	<xsl:variable name="c">
       
   263 		<xsl:choose>
       
   264 			<xsl:when test="contains(concat(' ',$class,' '),$r)">
       
   265 				<xsl:value-of select="substring-before(concat(' ',$class,' '),$r)"/>
       
   266 				<xsl:text> </xsl:text>
       
   267 				<xsl:value-of select="substring-after(concat(' ',$class,' '),$r)"/>
       
   268 			</xsl:when>
       
   269 			<xsl:otherwise><xsl:value-of select="$class"/></xsl:otherwise>
       
   270 		</xsl:choose>
       
   271 		<xsl:if test="normalize-space($add)!=''"><xsl:value-of select="concat(' ',normalize-space($add))"/></xsl:if>
       
   272 	</xsl:variable>
       
   273 	<xsl:choose>
       
   274 		<xsl:when test="contains($remove,' ')">
       
   275 			<xsl:call-template name="class">
       
   276 				<xsl:with-param name="remove" select="substring-after($remove,' ')"/>
       
   277 				<xsl:with-param name="class" select="$c"/>
       
   278 			</xsl:call-template>
       
   279 		</xsl:when>
       
   280 		<xsl:when test="normalize-space($c)!=''">
       
   281 			<xsl:attribute name="class">
       
   282 				<xsl:value-of select="normalize-space($c)"/>
       
   283 			</xsl:attribute>
       
   284 		</xsl:when>
       
   285 	</xsl:choose>
       
   286 </xsl:template>
       
   287 
       
   288 <xsl:template name="normpath"><xsl:param name="path"/>
       
   289 <!-- normalize out any ".." in the path in $path  -->
       
   290 <xsl:choose>
       
   291 	<xsl:when test="contains($path,'/../')">
       
   292 	<xsl:call-template name="normpath">
       
   293 		<xsl:with-param name="path">
       
   294 		<xsl:call-template name="before">
       
   295 			<xsl:with-param name="text" select="substring-before($path,'/../')"/>
       
   296 		</xsl:call-template>
       
   297 		<xsl:value-of select="substring-after($path,'/../')"/>
       
   298 		</xsl:with-param>
       
   299 		</xsl:call-template>
       
   300 	</xsl:when>
       
   301 	<xsl:otherwise><xsl:value-of select="$path"/></xsl:otherwise>
       
   302 </xsl:choose>
       
   303 </xsl:template>
       
   304 
       
   305 <!-- return all text before the last / -->
       
   306 <xsl:template name="before"><xsl:param name="text"/>
       
   307 <xsl:if test="contains($text,'/')">
       
   308 	<xsl:value-of select="substring-before($text,'/')"/>/<xsl:call-template name="before"><xsl:with-param name="text" select="substring-after($text,'/')"/></xsl:call-template>
       
   309 	</xsl:if>
       
   310 </xsl:template>
       
   311 
       
   312 <xsl:template name="DTD">
       
   313 <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE SystemDefinition [
       
   314 <!ELEMENT SystemDefinition ( systemModel )>
       
   315 <!ATTLIST SystemDefinition
       
   316   name CDATA #REQUIRED
       
   317   schema CDATA #REQUIRED
       
   318 >
       
   319 <!-- all paths are relative to the environment variable specified by the root attribute, or SOURCEROOT if not.  -->
       
   320 
       
   321 <!-- System Model Section of DTD -->
       
   322 <!ELEMENT systemModel (layer+)>
       
   323 
       
   324 <!ELEMENT layer (block* | collection*)*>
       
   325 <!-- Kernel Services, Base Services, OS Services, Etc -->
       
   326 <!ATTLIST layer
       
   327   name CDATA #REQUIRED
       
   328   long-name CDATA #IMPLIED
       
   329   levels NMTOKENS #IMPLIED
       
   330   span CDATA #IMPLIED
       
   331 >
       
   332 
       
   333 <!ELEMENT block (subblock* | collection*)*>
       
   334  <!-- Generic OS services, Comms Services, etc -->
       
   335 <!ATTLIST block
       
   336   levels NMTOKENS #IMPLIED
       
   337   span CDATA #IMPLIED
       
   338   level NMTOKEN #IMPLIED
       
   339   name CDATA #REQUIRED
       
   340   long-name CDATA #IMPLIED
       
   341 >
       
   342 
       
   343 <!ELEMENT subblock (collection)*>
       
   344 <!-- Cellular Baseband Services, Networking Services, etc -->
       
   345 <!ATTLIST subblock
       
   346   name CDATA #REQUIRED
       
   347   long-name CDATA #IMPLIED
       
   348 >
       
   349 
       
   350 <!ELEMENT collection (component)*>
       
   351 <!-- Screen Driver, Content Handling, etc -->
       
   352 <!ATTLIST collection
       
   353   name CDATA #REQUIRED
       
   354   long-name CDATA #IMPLIED
       
   355   level NMTOKEN #IMPLIED
       
   356 >
       
   357 
       
   358 <!ELEMENT component (unit)*>
       
   359 <!-- contains units or is a  package or prebuilt -->
       
   360 <!ATTLIST component
       
   361   name CDATA #REQUIRED
       
   362   long-name CDATA #IMPLIED
       
   363   deprecated CDATA #IMPLIED
       
   364   introduced CDATA #IMPLIED
       
   365   contract CDATA #IMPLIED
       
   366   plugin (Y|N) "N"
       
   367   filter CDATA #IMPLIED
       
   368   class NMTOKENS #IMPLIED
       
   369   supports CDATA #IMPLIED
       
   370   purpose ( optional | mandatory | development ) "optional"
       
   371 >
       
   372 
       
   373 <!ELEMENT unit EMPTY >
       
   374 <!-- must be buildable (bld.inf) -->
       
   375 <!-- bldFile  may someday be removed in favour of mrp -->
       
   376 <!ATTLIST unit
       
   377   mrp CDATA #IMPLIED
       
   378   filter CDATA #IMPLIED
       
   379   bldFile CDATA #IMPLIED
       
   380   root CDATA #IMPLIED
       
   381   version NMTOKEN #IMPLIED
       
   382   prebuilt NMTOKEN #IMPLIED
       
   383   late (Y|N) #IMPLIED
       
   384   priority CDATA #IMPLIED
       
   385 >
       
   386 ]>
       
   387 ]]></xsl:text>
       
   388 </xsl:template>
       
   389 </xsl:stylesheet>