sysdeftools/mergesysdef-module.xsl
branchHighFidelityModel
changeset 164 8309dda95234
parent 151 84b123918d3f
child 201 280dc2a9385b
equal deleted inserted replaced
163:c004c9299c6f 164:8309dda95234
    16 <xsl:variable name="defaultnamespace">http://www.symbian.org/system-definition</xsl:variable>
    16 <xsl:variable name="defaultnamespace">http://www.symbian.org/system-definition</xsl:variable>
    17 
    17 
    18 <xsl:template match="/SystemDefinition[starts-with(@schema,'2.') or starts-with(@schema,'1.')]" priority="2" mode="merge-models">
    18 <xsl:template match="/SystemDefinition[starts-with(@schema,'2.') or starts-with(@schema,'1.')]" priority="2" mode="merge-models">
    19 	<xsl:message terminate="yes">ERROR: Syntax <xsl:value-of select="@schema"/> not supported</xsl:message>
    19 	<xsl:message terminate="yes">ERROR: Syntax <xsl:value-of select="@schema"/> not supported</xsl:message>
    20 </xsl:template>
    20 </xsl:template>
    21 <xsl:template match="/SystemDefinition[not(systemModel)]" priority="2" mode="merge-models">
    21 <!--<xsl:template match="/SystemDefinition[not(systemModel)]" priority="2" mode="merge-models">
    22 	<xsl:message terminate="yes">ERROR: Can only merge stand-alone system models</xsl:message>
    22 	<xsl:message terminate="yes">ERROR: Can only merge stand-alone system models</xsl:message>
    23 </xsl:template>
    23 </xsl:template>-->
    24 
    24 
    25 <!-- stuff for dealing with namespaces -->
    25 <!-- stuff for dealing with namespaces -->
    26 
    26 
    27 
    27 
    28 <xsl:template match="node()|@*" mode="translate-namespaces"><xsl:copy-of select="."/></xsl:template>
    28 <xsl:template match="node()|@*" mode="translate-namespaces"><xsl:copy-of select="."/></xsl:template>
   128 	
   128 	
   129 	<!-- do some testing -->
   129 	<!-- do some testing -->
   130  	<xsl:if test="$other[starts-with(@schema,'2.') or starts-with(@schema,'1.')]">
   130  	<xsl:if test="$other[starts-with(@schema,'2.') or starts-with(@schema,'1.')]">
   131 		<xsl:message terminate="yes">ERROR: Syntax <xsl:value-of select="$other/@schema"/> not supported</xsl:message>
   131 		<xsl:message terminate="yes">ERROR: Syntax <xsl:value-of select="$other/@schema"/> not supported</xsl:message>
   132 	</xsl:if>
   132 	</xsl:if>
   133 	<xsl:if test="not($other/systemModel)">
   133 	<xsl:if test="name(*) != name($other/*)">
   134 		<xsl:message terminate="yes">ERROR: Can only merge stand-alone system models</xsl:message>
   134 		<xsl:message terminate="yes">ERROR: Can only merge system models of the same rank</xsl:message>
   135 	</xsl:if>
   135 	</xsl:if>
   136 	 
   136 	 
   137 	<xsl:copy>
   137 	<xsl:copy>
   138 		<xsl:copy-of  select="@*"/> <!--  use attributes from origin model -->
   138 		<xsl:copy-of  select="@*"/> <!--  use attributes from origin model -->
   139 		<xsl:variable name="namespaces">
   139 		<xsl:variable name="namespaces">
   224 		<xsl:when test="contains(concat(' ',normalize-space($other/@levels),' '),concat(' ',normalize-space(.),' '))">
   224 		<xsl:when test="contains(concat(' ',normalize-space($other/@levels),' '),concat(' ',normalize-space(.),' '))">
   225 			<!--  If this is contained is other, then use other-->
   225 			<!--  If this is contained is other, then use other-->
   226 			<xsl:copy-of select="$other/@levels"/>
   226 			<xsl:copy-of select="$other/@levels"/>
   227 		</xsl:when>
   227 		</xsl:when>
   228 		<xsl:when test="contains(concat(' ',normalize-space($other/@levels),' '),' - ')">
   228 		<xsl:when test="contains(concat(' ',normalize-space($other/@levels),' '),' - ')">
   229 			<!-- if other uses + syntax, then pre/append -->
   229 			<!-- if other uses - syntax, then pre/append -->
   230 			<xsl:variable name="lev">
   230 			<xsl:variable name="lev">
   231 				<xsl:value-of select="substring-before(concat(' ',normalize-space($other/@levels),' '),' - ')"/>
   231 				<xsl:value-of select="substring-before(concat(' ',normalize-space($other/@levels),' '),' - ')"/>
   232 				<xsl:value-of select="concat(' ',.,' ')"/>
   232 				<xsl:value-of select="concat(' ',.,' ')"/>
   233 				<xsl:value-of select="substring-after(concat(' ',normalize-space($other/@levels),' '),' - ')"/>
   233 				<xsl:value-of select="substring-after(concat(' ',normalize-space($other/@levels),' '),' - ')"/>
   234 			</xsl:variable>
   234 			</xsl:variable>
   314 			</xsl:call-template>
   314 			</xsl:call-template>
   315 		</xsl:when>	
   315 		</xsl:when>	
   316 	</xsl:choose>
   316 	</xsl:choose>
   317 </xsl:template>
   317 </xsl:template>
   318 
   318 
       
   319 <xsl:template match="node()" mode="merge-data">
       
   320 	<xsl:copy-of select="." />
       
   321 </xsl:template>
       
   322 
       
   323 <xsl:template match="meta" mode="merge-data">
       
   324 	<xsl:param name="metas" />
       
   325 	<!-- compare this meta against all metas in the  merged doc
       
   326 		if they are identical, then ignore this one.
       
   327 		identical is computed by translating to a string, normalising some known parts. This might be slow in some cases-->
       
   328 	<xsl:variable name="val"><xsl:apply-templates select="." mode="as-xml-text" /></xsl:variable>
       
   329 	<xsl:variable name="match">
       
   330 		<xsl:for-each select="$metas">
       
   331 			<xsl:variable name="cur"><xsl:apply-templates select="." mode="as-xml-text" /></xsl:variable>
       
   332 			<xsl:if test="$cur=$val">*</xsl:if>
       
   333 		</xsl:for-each>
       
   334 	</xsl:variable>
       
   335 	<xsl:if test="$match='' ">
       
   336 		<xsl:copy-of select="." />
       
   337 	</xsl:if>
       
   338 </xsl:template>
       
   339 
       
   340 <xsl:template match="text()[normalize-space(.)='']" mode="as-xml-text"/>
       
   341 <xsl:template match="node()" mode="as-xml-text"><xsl:value-of select="."/></xsl:template>
       
   342 <xsl:template match="comment()" mode="as-xml-text">&lt;--<xsl:value-of select="."/>--&gt;</xsl:template>
       
   343 <xsl:template match="@*" mode="as-xml-text">
       
   344 	<xsl:value-of select="concat(' ',name())"/>="<xsl:value-of select="."/>"</xsl:template>
       
   345 <xsl:template match="*" mode="as-xml-text">
       
   346 	<xsl:value-of select="concat('&lt;',name())"/>
       
   347 	<xsl:apply-templates select="@*" mode="as-xml-text"/>
       
   348 	<xsl:if test="self::meta and not(@rel)"> rel="Generic"</xsl:if>
       
   349 	<xsl:if test="self::meta and not(@type)"> type="auto"</xsl:if>
       
   350 	<xsl:text>&gt;</xsl:text>
       
   351 	<xsl:apply-templates select="node()" mode="as-xml-text"/>
       
   352 	<xsl:value-of select="concat('&lt;/',name(),'&gt;')"/>
       
   353 </xsl:template>
       
   354 
       
   355 
   319 <xsl:template match="layer | package | collection | component" mode="merge-models">
   356 <xsl:template match="layer | package | collection | component" mode="merge-models">
   320 	<xsl:param name="other"/>	<!-- the downstream item of the parent's rank that contains a potential items this is merged with -->
   357 	<xsl:param name="other"/>	<!-- the downstream item of the parent's rank that contains a potential items this is merged with -->
   321 	<xsl:param name="up"/>
   358 	<xsl:param name="up"/>
   322 	<xsl:param name="down"/>
   359 	<xsl:param name="down"/>
   323 	<xsl:variable name="this" select="."/>	<!-- current item -->
   360 	<xsl:variable name="this" select="."/>	<!-- current item -->
   324 	
   361 	
   325 	<!-- match = this item in the downstream model -->	
   362 	<!-- match = this item in the downstream model -->	
   326 	<xsl:variable name="match" select="$other/*[@id=current()/@id]"/>
   363 	<xsl:variable name="match" select="$other/*[@id=current()/@id]"/>
       
   364 	
   327 	
   365 	
   328 	<!-- prev = the previous item before the current one (no metas, only named items)-->
   366 	<!-- prev = the previous item before the current one (no metas, only named items)-->
   329 	<xsl:variable name="prev" select="preceding-sibling::*[@id][1]"/> 
   367 	<xsl:variable name="prev" select="preceding-sibling::*[@id][1]"/> 
   330 
   368 
   331 	<!-- copy all items between this and prev  that are solely in the downstream model -->	 		
   369 	<!-- copy all items between this and prev  that are solely in the downstream model -->	 		
   386 				<xsl:copy-of select="*|comment() | $match/meta |$match/unit[not($this/unit)] | $match/unit[$this/unit and @version[.!=$this/unit/@version]] | $match/comment()[.!=$this/comment()]"/>				
   424 				<xsl:copy-of select="*|comment() | $match/meta |$match/unit[not($this/unit)] | $match/unit[$this/unit and @version[.!=$this/unit/@version]] | $match/comment()[.!=$this/comment()]"/>				
   387 			</xsl:when>
   425 			</xsl:when>
   388 			<xsl:otherwise>
   426 			<xsl:otherwise>
   389 
   427 
   390 				<!--  copy metas and comments in between meta. Do not try to merge metadata between models -->
   428 				<!--  copy metas and comments in between meta. Do not try to merge metadata between models -->
   391 				<xsl:copy-of select="meta | $match/meta | comment()[following-sibling::meta]"/>
   429 				<xsl:apply-templates select="meta | $match/meta | comment()[following-sibling::meta]" mode="merge-data">
       
   430 					<xsl:with-param name="metas" select="$match/meta"/>
       
   431 				</xsl:apply-templates>
       
   432 				<xsl:copy-of select=" $match/meta | $match/comment()[following-sibling::meta]"/>
   392 				
   433 				
   393 				<xsl:apply-templates mode="merge-models">
   434 				<xsl:apply-templates mode="merge-models">
   394 					<xsl:with-param name="other" select="$match"/>
   435 					<xsl:with-param name="other" select="$match"/>
   395 					<xsl:with-param name="up" select="$up"/>
   436 					<xsl:with-param name="up" select="$up"/>
   396 					<xsl:with-param name="down" select="$down"/>
   437 					<xsl:with-param name="down" select="$down"/>