sysmodelgen/core/joinsysdef-module.xsl
branchHighFidelityModel
changeset 432 0f44a943faf9
parent 207 2fd8a273d6d6
equal deleted inserted replaced
429:cb270197b394 432:0f44a943faf9
    18  <xsl:variable name="defaultns">http://www.symbian.org/system-definition</xsl:variable>
    18  <xsl:variable name="defaultns">http://www.symbian.org/system-definition</xsl:variable>
    19  
    19  
    20 <!-- create a stand-alone sysdef from a linked set of fragments -->
    20 <!-- create a stand-alone sysdef from a linked set of fragments -->
    21 
    21 
    22 <xsl:template match="/*" mode="join">
    22 <xsl:template match="/*" mode="join">
    23 	<xsl:message terminate="yes">ERROR: Cannot process this document</xsl:message>
    23 	<xsl:param name="filename"/>
       
    24 	<xsl:message terminate="yes">ERROR: Cannot process this document<xsl:if test="$filename !=''"> (<xsl:value-of select="$filename"/>)</xsl:if>
       
    25 		<xsl:choose>
       
    26 			<xsl:when test="self::SystemDefinition/@schema">. Unrecognised syntax schema="<xsl:value-of select="@schema"/>"</xsl:when>
       
    27 			<xsl:when test="self::SystemDefinition">. Missing schema</xsl:when>
       
    28 			<xsl:otherwise>. Invalid file type: <xsl:value-of select="name()"/></xsl:otherwise>
       
    29 		</xsl:choose>
       
    30 	</xsl:message>
    24 </xsl:template>
    31 </xsl:template>
    25 
    32 
    26 <!-- anything in schemas 3.0.x won't add new functional attributes that need processing here, just blindly copy them-->
    33 <!-- anything in schemas 3.0.x won't add new functional attributes that need processing here, just blindly copy them-->
    27 
    34 
    28 <xsl:template match="/SystemDefinition[starts-with(@schema,'3.0.') and count(*)=1]" mode="join">
    35 <xsl:template match="/SystemDefinition[starts-with(@schema,'3.0.') and count(*)=1]" mode="join">
    45 				<xsl:for-each select="@*">
    52 				<xsl:for-each select="@*">
    46 					<xsl:variable name="n" select="name()"/>
    53 					<xsl:variable name="n" select="name()"/>
    47 					<xsl:choose>
    54 					<xsl:choose>
    48 						<xsl:when test="$n='id'"/> <!-- never copy this, always set -->
    55 						<xsl:when test="$n='id'"/> <!-- never copy this, always set -->
    49 						<xsl:when test="$origin/@*[name()=$n]"> <!-- don't copy if already set -->
    56 						<xsl:when test="$origin/@*[name()=$n]"> <!-- don't copy if already set -->
    50 							<xsl:message>Cannot set "<xsl:value-of select="$n"/>", already set</xsl:message>
    57 							<xsl:message>Note: Cannot set "<xsl:value-of select="$n"/>", already set on <xsl:value-of select="$origin/@id"/>. Ignoring linked value</xsl:message>
    51 						</xsl:when>
    58 						</xsl:when>
    52 						<xsl:when test="$n='before' or $n='replace'">
    59 						<xsl:when test="$n='before' or $n='replace'">
    53 							<!-- ensure ns is correct (if any future attribtues will ever use an ID, process it here too)-->
    60 							<!-- ensure ns is correct (if any future attribtues will ever use an ID, process it here too)-->
    54 							<xsl:apply-templates select="." mode="join">
    61 							<xsl:apply-templates select="." mode="join">
    55 								<xsl:with-param name="namespaces" select="$namespaces"/>
    62 								<xsl:with-param name="namespaces" select="$namespaces"/>
   124 
   131 
   125 <xsl:template match="*" mode="scan-for-namespaces"/> <!-- just in case of errors, consider replacing by terminate -->
   132 <xsl:template match="*" mode="scan-for-namespaces"/> <!-- just in case of errors, consider replacing by terminate -->
   126 <xsl:template match="*[@href and not(self::meta)]" mode="scan-for-namespaces">
   133 <xsl:template match="*[@href and not(self::meta)]" mode="scan-for-namespaces">
   127 	<!-- produce a list of namespace-prefix namespace pairs separated by newlines, in reverse order found in documents 
   134 	<!-- produce a list of namespace-prefix namespace pairs separated by newlines, in reverse order found in documents 
   128 		reverse order so we can try to use the first namespace prefix defined if it's available-->
   135 		reverse order so we can try to use the first namespace prefix defined if it's available-->
   129 	<xsl:for-each select="document(@href,.)/*">
   136 	<xsl:variable name="linked" select="document(@href,.)/*"/>
       
   137 	<xsl:for-each select="$linked">
   130 		<xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/>
   138 		<xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/>
   131 		<xsl:for-each select="//namespace::*[.!='http://www.w3.org/XML/1998/namespace'] | @id-namespace">
   139 		<xsl:for-each select="//namespace::*[.!='http://www.w3.org/XML/1998/namespace'] | @id-namespace">
   132 			<!-- ignore XML namespace -->
   140 			<!-- ignore XML namespace -->
   133 			<xsl:value-of select="concat(name(),' ',.,'&#xa;')"/>
   141 			<xsl:value-of select="concat(name(),' ',.,'&#xa;')"/>
   134 		</xsl:for-each>
   142 		</xsl:for-each>
   135 	</xsl:for-each>			
   143 	</xsl:for-each>
       
   144 	<xsl:if test="not($linked)">
       
   145 	<xsl:message>Note: The link to <xsl:value-of select="@href"/> from <xsl:value-of select="concat(name(),' ',@id)"/> could not be resolved. Perhaps there's an error in the XML?</xsl:message>
       
   146 	</xsl:if>
   136 </xsl:template>
   147 </xsl:template>
   137 
   148 
   138 <xsl:template name="needed-namespaces">
   149 <xsl:template name="needed-namespaces">
   139 	<xsl:param name="foundns"/>
   150 	<xsl:param name="foundns"/>
   140 	<xsl:param name="usedpre"/>
   151 	<xsl:param name="usedpre"/>
   141 	
   152 
   142 	<xsl:if test="$foundns!=''">
   153 	<xsl:if test="$foundns!=''">
   143 		<xsl:variable name="line" select="substring-before($foundns,'&#xa;')"/> <!-- always has trailing newline -->
   154 		<xsl:variable name="line" select="substring-before($foundns,'&#xa;')"/> <!-- always has trailing newline -->
   144 		<xsl:variable name="name" select="substring-after($line,' ')"/> <!-- namespace prefix -->
   155 		<xsl:variable name="name" select="substring-after($line,' ')"/> <!-- namespace prefix -->
   145 		<xsl:variable name="remainder" select="substring-after($foundns,'&#xa;')"/>
   156 		<xsl:variable name="remainder" select="substring-after($foundns,'&#xa;')"/>
   146 		<xsl:variable name="newprefix">
   157 		<xsl:variable name="newprefix">
   203 </xsl:attribute>
   214 </xsl:attribute>
   204 </xsl:template>
   215 </xsl:template>
   205 
   216 
   206 <xsl:template name="compare-versions"><xsl:param name="v1"/><xsl:param name="v2"/>
   217 <xsl:template name="compare-versions"><xsl:param name="v1"/><xsl:param name="v2"/>
   207 			<xsl:choose>
   218 			<xsl:choose>
   208 				<xsl:when test="$v1=$v2"><xsl:value-of select="$v1"/></xsl:when>
   219 				<xsl:when test="$v1=''"><xsl:value-of select="$v2"/></xsl:when>
       
   220 				<xsl:when test="$v1=$v2 or $v2=''"><xsl:value-of select="$v1"/></xsl:when>
   209 				<xsl:when test="substring-before($v1,'.') &gt; substring-before($v2,'.')"><xsl:value-of select="$v1"/></xsl:when>
   221 				<xsl:when test="substring-before($v1,'.') &gt; substring-before($v2,'.')"><xsl:value-of select="$v1"/></xsl:when>
   210 				<xsl:when test="substring-before($v1,'.') &lt; substring-before($v2,'.')"><xsl:value-of select="$v2"/></xsl:when>
   222 				<xsl:when test="substring-before($v1,'.') &lt; substring-before($v2,'.')"><xsl:value-of select="$v2"/></xsl:when>
   211 				<xsl:when test="substring-before(substring-after($v1,'.'),'.') &gt; substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when>
   223 				<xsl:when test="substring-before(substring-after($v1,'.'),'.') &gt; substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when>
   212 				<xsl:when test="substring-before(substring-after($v1,'.'),'.') &lt; substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v2"/></xsl:when>
   224 				<xsl:when test="substring-before(substring-after($v1,'.'),'.') &lt; substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v2"/></xsl:when>
   213 				<xsl:when test="substring-after(substring-after($v1,'.'),'.') &gt; substring-after(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when>
   225 				<xsl:when test="substring-after(substring-after($v1,'.'),'.') &gt; substring-after(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when>
   318 		 <xsl:variable name="href">
   330 		 <xsl:variable name="href">
   319 		 	<xsl:apply-templates select="." mode="link">
   331 		 	<xsl:apply-templates select="." mode="link">
   320 				<xsl:with-param name="data" select="$data"/>
   332 				<xsl:with-param name="data" select="$data"/>
   321 			</xsl:apply-templates>
   333 			</xsl:apply-templates>
   322 		 </xsl:variable>
   334 		 </xsl:variable>
       
   335 	 		 
   323 		<xsl:element name="{name()}"> <!-- use this instead of <copy> so xalan doesn't add extra wrong namespaces -->
   336 		<xsl:element name="{name()}"> <!-- use this instead of <copy> so xalan doesn't add extra wrong namespaces -->
   324 			<xsl:apply-templates select="@*" mode="join">
   337 			<xsl:apply-templates select="@*" mode="join">
   325 				<xsl:with-param name="namespaces" select="$namespaces"/>
   338 				<xsl:with-param name="namespaces" select="$namespaces"/>
   326 			</xsl:apply-templates>
   339 			</xsl:apply-templates>
   327 			<xsl:if test="$display != '' ">
   340 			<xsl:if test="$display != '' ">
   449 	<xsl:if test="$ns=''">
   462 	<xsl:if test="$ns=''">
   450 		<xsl:message terminate="yes">ERROR: Could not find namespace for <xsl:value-of select="name()"/> "<xsl:value-of select="."/>" in <xsl:apply-templates select="../.." mode="err-path"/>
   463 		<xsl:message terminate="yes">ERROR: Could not find namespace for <xsl:value-of select="name()"/> "<xsl:value-of select="."/>" in <xsl:apply-templates select="../.." mode="err-path"/>
   451 		<xsl:text>&#xa;</xsl:text>
   464 		<xsl:text>&#xa;</xsl:text>
   452 		</xsl:message>
   465 		</xsl:message>
   453 	</xsl:if>
   466 	</xsl:if>
   454 
       
   455 	<xsl:variable name="prefix" select="name($namespaces[.=$ns])"/>
   467 	<xsl:variable name="prefix" select="name($namespaces[.=$ns])"/>
   456 	<xsl:attribute name="{name()}">
   468 	<xsl:attribute name="{name()}">
   457 	<xsl:choose>
   469 	<xsl:choose>
   458 
       
   459 		<xsl:when test="$prefix = 'id-namespace' or  (not($namespaces[name()='id-namespace']) and $ns=$defaultns)"/> <!-- it's the default namespace, no prefix -->
   470 		<xsl:when test="$prefix = 'id-namespace' or  (not($namespaces[name()='id-namespace']) and $ns=$defaultns)"/> <!-- it's the default namespace, no prefix -->
   460 		<xsl:when test="$prefix='' and contains(.,':')">
   471 		<xsl:when test="$prefix='' and contains(.,':')">
   461 			<!-- complex: copy id and copy namespace (namespace should be copied already)-->
   472 			<!-- complex: copy id and copy namespace (namespace should be copied already)-->
   462 			<xsl:value-of select="."/>
   473 			<xsl:value-of select="."/>
   463 		</xsl:when>
   474 		</xsl:when>
   477 
   488 
   478 
   489 
   479 <xsl:template match="@*|comment()" mode="join"><xsl:copy-of select="."/></xsl:template>
   490 <xsl:template match="@*|comment()" mode="join"><xsl:copy-of select="."/></xsl:template>
   480 
   491 
   481 
   492 
   482 <!-- path handling follows -->
   493 <xsl:include href="path-module.xsl"/>
   483 
       
   484  <xsl:template name="lastbefore"><xsl:param name="string"/><xsl:param name="substr" select="'/'"/>
       
   485         <xsl:if test="contains($string,$substr)">
       
   486                 <xsl:value-of select="substring-before($string,$substr)"/>
       
   487                 <xsl:if test="contains(substring-after($string,$substr),$substr)">
       
   488 	                <xsl:value-of select="$substr"/>
       
   489 	              </xsl:if>
       
   490         <xsl:call-template name="lastbefore">
       
   491                 <xsl:with-param name="string" select="substring-after($string,$substr)"/>
       
   492                 <xsl:with-param name="substr" select="$substr"/>
       
   493         </xsl:call-template>
       
   494         </xsl:if>
       
   495 </xsl:template>
       
   496 
       
   497  <xsl:template name="joinpath"><xsl:param name="file"/><xsl:param name="rel"/>
       
   498 	<xsl:choose>
       
   499 		<xsl:when test="(contains($rel,'://') and not(contains(substring-before($rel,'://'),'/'))) or starts-with($rel,'/')"> <!-- absolute URI or absolute path-->
       
   500 			<xsl:value-of select="$rel"/>
       
   501 		</xsl:when>
       
   502 		<xsl:otherwise> <!-- relative link -->
       
   503 			<xsl:call-template name="reducepath">
       
   504 				<xsl:with-param name="file">
       
   505 					<xsl:call-template name="lastbefore">
       
   506 						<xsl:with-param name="string" select="$file"/>
       
   507 					</xsl:call-template>
       
   508 					<xsl:text>/</xsl:text>
       
   509 					<xsl:value-of select="$rel"/>
       
   510 				</xsl:with-param>
       
   511 			</xsl:call-template>
       
   512 		</xsl:otherwise>
       
   513 	</xsl:choose>
       
   514  </xsl:template>
       
   515 
       
   516 <xsl:template name="reducepath"><xsl:param name="file"/>
       
   517 	<xsl:call-template name="reducedotdotpath">
       
   518     	<xsl:with-param name="file">
       
   519 			<xsl:call-template name="reducedotpath">
       
   520 		    	<xsl:with-param name="file" select="$file"/>
       
   521 		    </xsl:call-template>
       
   522 		</xsl:with-param>
       
   523 	</xsl:call-template>
       
   524 </xsl:template>
       
   525 
       
   526 <xsl:template name="reducedotdotpath"><xsl:param name="file"/>
       
   527 	<xsl:choose>
       
   528 		<xsl:when test="starts-with($file,'../')">
       
   529 			<xsl:text>../</xsl:text>
       
   530 			<xsl:call-template name="reducedotdotpath">
       
   531         		<xsl:with-param name="file" select="substring($file,4)"/>
       
   532 			</xsl:call-template>
       
   533 		</xsl:when>
       
   534 		<xsl:when test="contains($file,'/../')">							
       
   535 			<xsl:call-template name="reducepath">
       
   536         		<xsl:with-param name="file">
       
   537 			        <xsl:call-template name="lastbefore">
       
   538 			                <xsl:with-param name="string" select="substring-before($file,'/../')"/>
       
   539 			        </xsl:call-template>
       
   540 			        <xsl:text>/</xsl:text>
       
   541 					<xsl:value-of select="substring-after($file,'/../')"/>
       
   542 				</xsl:with-param>
       
   543 			</xsl:call-template>
       
   544 		</xsl:when>
       
   545 		<xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise>
       
   546 	</xsl:choose>
       
   547  </xsl:template>
       
   548 
       
   549 <xsl:template name="reducedotpath"><xsl:param name="file"/>
       
   550 	<xsl:choose>	
       
   551 		<xsl:when test="starts-with($file,'./')">
       
   552 			<xsl:call-template name="reducedotpath">
       
   553         		<xsl:with-param name="file" select="substring($file,3)"/>
       
   554 			</xsl:call-template>
       
   555 		</xsl:when>
       
   556 		<xsl:when test="contains($file,'/./')">
       
   557 			<xsl:call-template name="reducepath">
       
   558         		<xsl:with-param name="file">
       
   559 	                <xsl:value-of select="substring-before($file,'/./')"/>
       
   560 			        <xsl:text>/</xsl:text>
       
   561 					<xsl:value-of select="substring-after($file,'/./')"/>
       
   562 				</xsl:with-param>
       
   563 			</xsl:call-template>
       
   564 		</xsl:when>
       
   565 		<xsl:when test="substring($file,string-length($file) - 1) = '/.'">
       
   566            <xsl:value-of select="substring($file,1,string-length($file) - 2)"/>
       
   567 		</xsl:when>
       
   568 		<xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise>
       
   569 	</xsl:choose>
       
   570  </xsl:template>
       
   571 
   494 
   572 <!-- overridable templates follow -->
   495 <!-- overridable templates follow -->
   573 
   496 
   574 
   497 
   575 <xsl:template match="*" mode="filter" priority="-9"/> <!-- by default show --> 
   498 <xsl:template match="*" mode="filter" priority="-9"/> <!-- by default show -->