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