buildframework/helium/sf/java/sysdef/demo/data/sf/os/buildtools/bldsystemtools/sysdeftools/mergesysdef.xsl
changeset 628 7c4a911dc066
parent 587 85df38eb4012
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
     1 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common">
     1 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt">
     2 <!--Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 <!--Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 	All rights reserved.
     3 	All rights reserved.
     4 	This component and the accompanying materials are made available
     4 	This component and the accompanying materials are made available
     5 	under the terms of "Eclipse Public License v1.0"
     5 	under the terms of the License "Eclipse Public License v1.0"
     6 	which accompanies this distribution, and is available
     6 	which accompanies this distribution, and is available
     7 	at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 	at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 
     8 
     9 	Initial Contributors:
     9 	Initial Contributors:
    10 	Nokia Corporation - initial contribution.
    10 	Nokia Corporation - initial contribution.
    11 	Contributors:
    11 	Contributors:
    12 	Description:
    12 	Description:
    13 	Merge two 3.x syntax system definitions
    13 	Merge two 3.x syntax system definitions
    14 -->
    14 -->
    15 
    15 
       
    16 <!--Description:This merges two 3.x syntax system definitions.
       
    17 It can process two standalone sysdefs or two sysdef fragments which describe
       
    18 the same system model item.
       
    19 If the sysdefs are not the same schema, the output will use the highest schema
       
    20 value of the two.
       
    21 -->
       
    22 <!--Input:<sysdef> - (required) The system definition XML file to process in the 3.0 format, and can be a fragment or stand-alone.
       
    23 	If a fragment, this must be the same rank as the Downstream sysdef-->
       
    24 <!--Output:<sysdef> - (optional) The system definition XML file to save the output as. If not present it will write to stdout.-->
       
    25 
    16 	<xsl:output method="xml" indent="yes"/>
    26 	<xsl:output method="xml" indent="yes"/>
    17 	<xsl:param name="Downstream">mcl/System_Definition_Template.xml</xsl:param>
    27 	<xsl:param name="Downstream">mcl/System_Definition_Template.xml</xsl:param> <!-- <sysdef> - (required) The path to the downstream systef relative to the upstream one (ie the -in sysdef). -->
    18 	<xsl:key name="origin" match="component" use="@origin-model"/>
    28 	<xsl:key name="origin" match="component" use="@origin-model"/>
    19 
       
    20 <!-- only supports 3.x syntax and only operates on stand-alone models -->
       
    21 
    29 
    22 <xsl:variable name="downstream" select="document($Downstream,.)/SystemDefinition"/>
    30 <xsl:variable name="downstream" select="document($Downstream,.)/SystemDefinition"/>
    23 <xsl:param name="upname">
    31 <xsl:param name="upname">
    24 	<xsl:choose>
    32 	<xsl:choose>
    25 		<xsl:when test="$downstream[starts-with(@schema,'2.') or starts-with(@schema,'1.')  or not(systemModel)]">
    33 		<xsl:when test="$downstream[starts-with(@schema,'2.') or starts-with(@schema,'1.')]">
    26 			<xsl:message terminate="yes">Syntax <xsl:value-of select="@schema"/> not supported</xsl:message>
    34 			<xsl:message terminate="yes">Syntax <xsl:value-of select="@schema"/> not supported</xsl:message>
    27 		</xsl:when>
    35 		</xsl:when>
    28 		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name">
    36 		<xsl:when test="name($downstream/*)!=name(/SystemDefinition/*)">
       
    37 			<xsl:message terminate="yes">Can only merge fragments of the same rank</xsl:message>
       
    38 		</xsl:when>
       
    39 <!--		<xsl:when test="$downstream[not(systemModel)]">
       
    40 			<xsl:message terminate="yes">Needs to be a standalone system definition</xsl:message>
       
    41 		</xsl:when>-->
       
    42 		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name or not(/SystemDefinition/systemModel/@name)">
    29 			<xsl:apply-templates mode="origin-term" select="/*">
    43 			<xsl:apply-templates mode="origin-term" select="/*">
    30 				<xsl:with-param name="root">Upstream</xsl:with-param>
    44 				<xsl:with-param name="root">Upstream</xsl:with-param>
    31 			</xsl:apply-templates>
    45 			</xsl:apply-templates>
    32 			</xsl:when>
    46 			</xsl:when>
    33 		<xsl:otherwise><xsl:value-of select="/SystemDefinition/systemModel/@name"/></xsl:otherwise>
    47 		<xsl:otherwise><xsl:value-of select="/SystemDefinition/systemModel/@name"/></xsl:otherwise>
    34 	</xsl:choose>
    48 	</xsl:choose>
    35 </xsl:param>
    49 </xsl:param>
       
    50 <!-- [name] - (optional) The name used in the origin-model attribute of any component that comes from the upstream sysdef. Defaults to the name attribute on the systemModel element, or "Upstream"-->
    36 
    51 
    37 <xsl:param name="downname">
    52 <xsl:param name="downname">
    38 	<xsl:choose>
    53 	<xsl:choose>
    39 		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name">
    54 		<xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name or not($downstream/systemModel/@name)">
    40 			<xsl:apply-templates mode="origin-term" select="$downstream">	
    55 			<xsl:apply-templates mode="origin-term" select="$downstream">	
    41 				<xsl:with-param name="root">Downstream</xsl:with-param>
    56 				<xsl:with-param name="root">Downstream</xsl:with-param>
    42 			</xsl:apply-templates>
    57 			</xsl:apply-templates>
    43 			</xsl:when>
    58 			</xsl:when>
       
    59 		<xsl:when test="name($downstream/*)!=name(/SystemDefinition/*)">
       
    60 			<xsl:message terminate="yes">Can only merge fragments of the same rank</xsl:message>
       
    61 		</xsl:when>
    44 		<xsl:otherwise><xsl:value-of select="$downstream/systemModel/@name"/></xsl:otherwise>
    62 		<xsl:otherwise><xsl:value-of select="$downstream/systemModel/@name"/></xsl:otherwise>
    45 	</xsl:choose>
    63 	</xsl:choose>
    46 </xsl:param>
    64 </xsl:param>
       
    65 <!-- [name] - (optional) The name used in the origin-model attribute of any component that comes from the downstream sysdef. Defaults to the name attribute on the systemModel element, or "Downstream"-->
    47 
    66 
    48 <xsl:template mode="origin-term" match="*">
    67 <xsl:template mode="origin-term" match="*">
    49 	<xsl:param name="root"/>
    68 	<xsl:param name="root"/>
    50 	<xsl:param name="index"/>
    69 	<xsl:param name="index"/>
    51 	<xsl:choose>
    70 	<xsl:choose>
    66 		</xsl:otherwise>
    85 		</xsl:otherwise>
    67 	</xsl:choose>
    86 	</xsl:choose>
    68 </xsl:template>
    87 </xsl:template>
    69 
    88 
    70 
    89 
    71 <!--  this merge only two files according to the 3.0.0 rules. Old syntax not supported. Must be converetd before calling -->
    90 <!-- choose the greater of the two versions -->
       
    91 <xsl:template name="compare-versions"><xsl:param name="v1"/><xsl:param name="v2"/>
       
    92 			<xsl:choose>
       
    93 				<xsl:when test="$v1=$v2"><xsl:value-of select="$v1"/></xsl:when>
       
    94 				<xsl:when test="substring-before($v1,'.') &gt; substring-before($v2,'.')"><xsl:value-of select="$v1"/></xsl:when>
       
    95 				<xsl:when test="substring-before($v1,'.') &lt; substring-before($v2,'.')"><xsl:value-of select="$v2"/></xsl:when>
       
    96 				<xsl:when test="substring-before(substring-after($v1,'.'),'.') &gt; substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when>
       
    97 				<xsl:when test="substring-before(substring-after($v1,'.'),'.') &lt; substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v2"/></xsl:when>
       
    98 				<xsl:when test="substring-after(substring-after($v1,'.'),'.') &gt; substring-after(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when>
       
    99 				<xsl:when test="substring-after(substring-after($v1,'.'),'.') &lt; substring-after(substring-after($v2,'.'),'.')"><xsl:value-of select="$v2"/></xsl:when>
       
   100 				<xsl:otherwise><xsl:value-of select="$v1"/></xsl:otherwise>
       
   101 			</xsl:choose>
       
   102 </xsl:template>
       
   103 
       
   104 <!--  this merge only two files according to the 3.0.x rules. Old syntax not supported. Must be converetd before calling -->
    72 
   105 
    73 
   106 
    74 
   107 
    75 <xsl:template match="/*">
   108 <xsl:template match="/*">
    76 	<xsl:variable name="upmodel">
   109 	<xsl:variable name="upmodel">
    77 		<sysdef name="{$upname}"/>
   110 		<sysdef name="{$upname}"/>
    78 	</xsl:variable>
   111 	</xsl:variable>
    79 	<xsl:variable name="downmodel">
   112 	<xsl:variable name="downmodel">
    80 		<sysdef name="{$downname}"/>
   113 		<sysdef name="{$downname}" pathto="{$Downstream}"/>
    81 	</xsl:variable>
   114 	</xsl:variable>
    82 	
   115 	
    83 	<xsl:choose>
   116 	<xsl:choose>
    84 		<xsl:when test="function-available('exslt:node-set')">
   117 		<xsl:when test="function-available('exslt:node-set')">
    85 			<xsl:apply-templates mode="merge-models" select=".">
   118 			<xsl:apply-templates mode="merge-models" select=".">
    94 			</xsl:apply-templates> 		
   127 			</xsl:apply-templates> 		
    95 		</xsl:otherwise>
   128 		</xsl:otherwise>
    96 	</xsl:choose>
   129 	</xsl:choose>
    97 </xsl:template>
   130 </xsl:template>
    98 
   131 
    99 <xsl:include href="mergesysdef-module.xsl"/>
   132 <xsl:include href="lib/path-module.xsl"/>
       
   133 <xsl:include href="lib/mergesysdef-module.xsl"/>
       
   134 
       
   135 <xsl:template match="@*[local-name()='proFile' or local-name()='qmakeArgs'  or namespace-uri()='qt']" mode="merge-copy-of">
       
   136 	<!-- this fixes a xalan-j issue where it changes the namespace in the merged model to just "qt"-->
       
   137 	<xsl:attribute name="{local-name()}" namespace="http://www.nokia.com/qt">
       
   138 		<xsl:value-of select="."/>
       
   139 	</xsl:attribute>
       
   140 </xsl:template>
       
   141 
   100 </xsl:stylesheet>
   142 </xsl:stylesheet>