common/sysdefdowngrade/sysdefdowngrade.xsl
changeset 853 bde28f2b1d99
parent 319 257557b39754
equal deleted inserted replaced
852:41f42b520ea7 853:bde28f2b1d99
     1 <?xml version="1.0" encoding="UTF-8"?>
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     2  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     3 	<xsl:output method="xml" indent="yes"/>
     3 	<xsl:output method="xml" indent="yes"/>
     4 	
     4 	
     5 	<xsl:param name="Path">os/deviceplatformrelease/foundation_system/system_model</xsl:param>
     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 /
     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-->
     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 -->
     8 
    11 
     9 <xsl:template match="/*">
    12 <xsl:template match="/*">
    10 	<xsl:message terminate="yes">Cannot process this document</xsl:message>
    13 	<xsl:message terminate="yes">Cannot process this document</xsl:message>
    11 </xsl:template>
    14 </xsl:template>
    12 
    15 
    51 <xsl:template match="/"><xsl:apply-templates select="*"/></xsl:template>
    54 <xsl:template match="/"><xsl:apply-templates select="*"/></xsl:template>
    52 <xsl:template match="@*|comment()"><xsl:copy-of select="."/></xsl:template> 
    55 <xsl:template match="@*|comment()"><xsl:copy-of select="."/></xsl:template> 
    53 	<!-- comments are copied verbatim. Attribtues are copied by default -->
    56 	<!-- comments are copied verbatim. Attribtues are copied by default -->
    54 
    57 
    55 <xsl:template match="systemModel">
    58 <xsl:template match="systemModel">
    56 	<xsl:copy>
    59 	<systemModel>
    57   	<xsl:apply-templates select="*|comment()"> <!-- no attributes -->
    60   	<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 -->
    61   		<xsl:with-param name="path" select="$Path"/> <!-- need to keep tack of where the current document is -->
    59   	</xsl:apply-templates>
    62   	</xsl:apply-templates>
    60 	</xsl:copy>
    63 	</systemModel>
    61 </xsl:template>
    64 </xsl:template>
    62 
    65 
    63 <xsl:template mode="copy" match="@*">
    66 <xsl:template mode="copy" match="@*">
    64 	<xsl:copy-of select="."/>
    67 	<xsl:copy-of select="."/>
    65 </xsl:template>
    68 </xsl:template>
    89 		<xsl:apply-templates mode="copy" select="@id|@name|@span|@level|@levels"/><!--  valid attribuites for 2.0 -->
    92 		<xsl:apply-templates mode="copy" select="@id|@name|@span|@level|@levels"/><!--  valid attribuites for 2.0 -->
    90 		<xsl:choose>
    93 		<xsl:choose>
    91 			<xsl:when test="@href">
    94 			<xsl:when test="@href">
    92 				<xsl:variable name="this" select="."/>
    95 				<xsl:variable name="this" select="."/>
    93 				<xsl:for-each select="document(@href,.)/SystemDefinition/*">
    96 				<xsl:for-each select="document(@href,.)/SystemDefinition/*">
    94 					<xsl:if test="@id!=$this/@id">
    97 					<xsl:variable name="my-id"><xsl:apply-templates mode="normalize-id" select="@id"/></xsl:variable>
    95 						<xsl:message terminate="yes">Error: IDs do not match: <xsl:value-of select="@id"/> vs <xsl:value-of select="$this/@id"/></xsl:message>
    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>
    96 					</xsl:if>
   101 					</xsl:if>
    97 					<xsl:if test="@name and @name!=@id and not($this/@name and $this/@name=$this/@id)">
   102 					<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 -->
   103 						<!-- 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>
   104 						<xsl:attribute name="long-name"><xsl:value-of select="@name"/></xsl:attribute>
   100 					</xsl:if>						
   105 					</xsl:if>						
   173 <xsl:template match="unit"><xsl:param name="path"/>
   178 <xsl:template match="unit"><xsl:param name="path"/>
   174 	<unit>
   179 	<unit>
   175 		<xsl:apply-templates select="@mrp|@bldFile|@late">
   180 		<xsl:apply-templates select="@mrp|@bldFile|@late">
   176 			<xsl:with-param name="path" select="$path"/> 
   181 			<xsl:with-param name="path" select="$path"/> 
   177 		</xsl:apply-templates>
   182 		</xsl:apply-templates>
   178 		<xsl:copy-of select="@filter|@root|@version|@prebuilt|@priority"/>
   183 		<xsl:copy-of select="@filter|@root[not(contains($root,concat(' ',.,'=')))]|@version|@prebuilt|@priority"/>
   179 	</unit>
   184 	</unit>
   180 </xsl:template>
   185 </xsl:template>
   181 
   186 
   182 <xsl:template match="unit/@late"> <!-- 2.0 uses Y/N, 3.0 uses yes/no -->
   187 <xsl:template match="unit/@late"> <!-- 2.0 uses Y/N, 3.0 uses yes/no -->
   183 	<xsl:attribute name="{name()}">
   188 	<xsl:attribute name="{name()}">
   188 	</xsl:attribute>
   193 	</xsl:attribute>
   189 </xsl:template>
   194 </xsl:template>
   190 
   195 
   191 <xsl:template match="@mrp|@bldFile"><xsl:param name="path"/>
   196 <xsl:template match="@mrp|@bldFile"><xsl:param name="path"/>
   192 	<xsl:attribute name="{name()}">
   197 	<xsl:attribute name="{name()}">
   193 	<xsl:choose>
   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>
   194 		<xsl:when test="starts-with(.,'/')"> <!-- keep absolute paths verbatim (barring the leading / ) -->
   208 		<xsl:when test="starts-with(.,'/')"> <!-- keep absolute paths verbatim (barring the leading / ) -->
   195 			<xsl:value-of select="substring-after(substring(.,2),'/')"/>
   209 			<xsl:value-of select="substring-after(.,'/')"/>
   196 		</xsl:when>
   210 		</xsl:when>
   197 		<xsl:otherwise>	
   211 		<xsl:otherwise>	
   198 			<xsl:call-template name="normpath">
   212 			<xsl:call-template name="normpath">
   199   				<xsl:with-param name="path">
   213   				<xsl:with-param name="path">
   200   					<xsl:call-template name="before">
   214   					<xsl:call-template name="before">
   210 
   224 
   211 <xsl:template match="meta"/> <!-- strip all meta tags -->
   225 <xsl:template match="meta"/> <!-- strip all meta tags -->
   212 
   226 
   213 <xsl:template match="meta[info/@contract]"> <!-- except contract -->
   227 <xsl:template match="meta[info/@contract]"> <!-- except contract -->
   214 	<xsl:copy-of select="info/@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>
   215 </xsl:template>
   236 </xsl:template>
   216 
   237 
   217 <xsl:template name="class"><xsl:param name="remove"/><xsl:param name="add"/>
   238 <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) -->
   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) -->
   219 	<xsl:param name="class" select="normalize-space(@class)"/>
   240 	<xsl:param name="class" select="normalize-space(@class)"/>