buildframework/helium/external/helium-antlib/sysdef/demo/data/sf/os/buildtools/bldsystemtools/buildsystemtools/mergesysdef-module.xsl
author wbernard
Wed, 23 Dec 2009 19:29:07 +0200
changeset 179 d8ac696cc51f
permissions -rw-r--r--
helium_7.0-r14027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     1
<!-- 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     2
============================================================================ 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     3
Name        : mergesysdef-module.xsl 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     4
Part of     : Helium AntLib
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     5
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     6
Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     7
All rights reserved.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     8
This component and the accompanying materials are made available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     9
under the terms of the License "Eclipse Public License v1.0"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    10
which accompanies this distribution, and is available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    11
at the URL "http://www.eclipse.org/legal/epl-v10.html".
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    12
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    13
Initial Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    14
Nokia Corporation - initial contribution.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    15
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    16
Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    17
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    18
Description:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    19
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    20
============================================================================
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    21
-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    22
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common"  exclude-result-prefixes="exslt">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    23
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    24
<!--  this merge only two files according to the 3.0.0 rules. Old syntax not supported. Must be converetd before calling -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    25
<xsl:variable name="defaultns">http://www.symbian.org/system-definition</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    26
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    27
<xsl:template match="/SystemDefinition[starts-with(@schema,'2.') or starts-with(@schema,'1.')]" priority="2" mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    28
	<xsl:message terminate="yes">Syntax <xsl:value-of select="@schema"/> not supported</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    29
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    30
<xsl:template match="/SystemDefinition[not(systemModel)]" priority="2" mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    31
	<xsl:message terminate="yes">Can only merge stand-alone system models</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    32
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    33
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    34
<!-- stuff for dealing with namespaces -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    35
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    36
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    37
<xsl:template match="node()|@*" mode="translate-namespaces"><xsl:copy-of select="."/></xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    38
<!-- don't translate meta or unit tags, just copy verbatim -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    39
<xsl:template match="meta|unit" mode="translate-namespaces" priority="2">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    40
<xsl:element name="{name()}">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    41
<xsl:copy-of select="@*|*|comment()"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    42
</xsl:element>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    43
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    44
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    45
<xsl:template match="*" mode="translate-namespaces"><xsl:param name="nsdoc"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    46
<xsl:element name="{name()}">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    47
<xsl:apply-templates select="@*|node()" mode="translate-namespaces">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    48
	<xsl:with-param name="nsdoc" select="$nsdoc"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    49
</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    50
</xsl:element>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    51
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    52
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    53
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    54
<xsl:template match="@id|@before" mode="translate-namespaces"><xsl:param name="nsdoc"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    55
	<xsl:attribute name="{name()}">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    56
		<xsl:variable name="id">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    57
			<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    58
				<xsl:when test="contains(.,':')">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    59
					<xsl:value-of select="substring-after(.,':')"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    60
				</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    61
				<xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    62
					<xsl:value-of select="."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    63
				</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    64
			</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    65
		</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    66
		<xsl:variable name="ns">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    67
			<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    68
				<xsl:when test="contains(.,':')">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    69
					<xsl:value-of select="ancestor-or-self::*/namespace::*[name()=substring-before(current()/.,':')]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    70
				</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    71
				<xsl:when test="/SystemDefinition/@id-namespace">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    72
					<xsl:value-of select="/SystemDefinition/@id-namespace"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    73
				</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    74
				<xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    75
					<xsl:value-of select="$defaultns"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    76
				</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    77
			</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    78
		</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    79
		<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    80
			<xsl:when test="not($nsdoc/@id-namespace) and $defaultns=$ns">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    81
				<xsl:value-of select="$id"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    82
			</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    83
			<xsl:when test="$nsdoc/@id-namespace=$ns">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    84
				<xsl:value-of select="$id"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    85
			</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    86
			<xsl:when test="$nsdoc/namespace::*[.=$ns]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    87
				<xsl:value-of select="concat(name($nsdoc/namespace::*[.=$ns]),':',$id)"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    88
			</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    89
			<xsl:when test="/SystemDefinition/@id-namespace=$ns">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    90
				<xsl:variable name="myns">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    91
					<xsl:apply-templates mode="ns-prefix" select="$nsdoc">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    92
						<xsl:with-param name="ns" select="$ns"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    93
					</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    94
				</xsl:variable>			
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    95
				<xsl:value-of select="concat($myns,':',$id)"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    96
			</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    97
			<xsl:otherwise> <!-- some namespace that needed to be defined --> 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    98
			<xsl:message>"<xsl:value-of select="$ns"/>" for <xsl:value-of select="$id"/></xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    99
				<xsl:value-of select="."/>					
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   100
			</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   101
		</xsl:choose>		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   102
	</xsl:attribute>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   103
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   104
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   105
<xsl:template match="/SystemDefinition" mode="ns-prefix">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   106
	<xsl:param name="ns"/> <!-- the namespace URI -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   107
	<xsl:param name="pre"/> <!-- the preferred prefix to use if possbile -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   108
	<xsl:param name="dontuse"/> <!-- space prefixed, separated and terminated list of namespace prefixes to not use -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   109
	<xsl:param name="chars">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:param> <!-- single letter namespace prefixes to try -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   110
	<xsl:variable name="name" select="substring(substring-after($ns,'http://www.'),1,1)"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   111
	<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   112
		<xsl:when test="$pre!='' and $pre!='id-namespace' and not(//namespace::*[name()=$pre]) and not(contains($dontuse,concat(' ',$pre,' ')))">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   113
			<xsl:value-of select="$pre"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   114
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   115
		<xsl:when test="$ns='' and $chars=''">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   116
			<xsl:message terminate="yes">Cannot create namespace prefix for downstream default namespace</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   117
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   118
		<xsl:when test="$name!='' and not(contains($dontuse,concat(' ',$name,' ')))"><xsl:value-of select="$name"/></xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   119
		<xsl:when test="namespace::*[name()=substring($chars,1,1)] or contains($dontuse,concat(' ',substring($chars,1,1),' '))">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   120
			<xsl:apply-templates mode="ns-prefix">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   121
				<xsl:with-param name="chars" select="substring($chars,2)"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   122
			</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   123
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   124
		<xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   125
			<xsl:value-of select="substring($chars,1,1)"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   126
		</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   127
	</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   128
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   129
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   130
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   131
<!--  need to make sure this handles <meta> correctly -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   132
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   133
<xsl:template match="/SystemDefinition" mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   134
	<xsl:param name="other"/>	<!-- the downstream SystemDefinition this is merged with -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   135
	<xsl:param name="up" select="systemModel"/>	<!-- the element containing the origin @name used for any component from "this" model. -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   136
	<xsl:param name="down" select="$other/systemModel"/> <!-- the element containing origin @name used for any component from $other model. -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   137
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   138
	<!-- do some testing -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   139
 	<xsl:if test="$other[starts-with(@schema,'2.') or starts-with(@schema,'1.')]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   140
		<xsl:message terminate="yes">Syntax <xsl:value-of select="$other/@schema"/> not supported</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   141
	</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   142
	<xsl:if test="not($other/systemModel)">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   143
		<xsl:message terminate="yes">Can only merge stand-alone system models</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   144
	</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   145
	 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   146
	<xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   147
		<xsl:copy-of  select="@*"/> <!--  use attributes from origin model -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   148
		<xsl:variable name="namespaces">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   149
			<xsl:copy> <!-- needs <copy> so the processor doesn't lose the namespaces -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   150
				<!--copy namespaces as needed -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   151
				
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   152
				<xsl:copy-of select="namespace::*[name()!='xml']"/> <!-- all upstream namespaces -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   153
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   154
				<xsl:variable name="cur" select="."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   155
				<xsl:for-each select="$other/namespace::*"> <!-- all namespaces in downstream not already in upstream -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   156
					<xsl:if test="not((. = $cur/@id-namespace) or (not($cur/@id-namespace) and .= $defaultns) or  $cur/namespace::*[.=current()])">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   157
							<!-- namespace in downstream not in upstream doc -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   158
							<xsl:variable name="newprefix">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   159
								 <!-- test to see if the ns prefix already exists -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   160
								<xsl:apply-templates select="$cur" mode="ns-prefix">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   161
									<xsl:with-param name="ns" select="."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   162
									<xsl:with-param name="pre" select="name()"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   163
								</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   164
							</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   165
							<xsl:copy/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   166
					</xsl:if>   
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   167
				</xsl:for-each>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   168
				
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   169
					<xsl:if test="not(($other/@id-namespace = @id-namespace) or (not($other/@id-namespace) and not(@id-namespace)) or (not(@id-namespace) and $other/@id-namespace = $defaultns) or namespace::*[.=$other/@id-namespace])">  
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   170
						<!-- default namespace in downstream not in upstream doc -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   171
						<!-- need to make created ns a bit more intelligent -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   172
						<xsl:attribute name="bar" namespace="{$other/@id-namespace}">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   173
							<xsl:value-of select="$other/@id-namespace"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   174
						</xsl:attribute>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   175
				</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   176
			</xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   177
		</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   178
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   179
		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   180
		<!-- copy the namespaces to currently open element (the root one) -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   181
		<xsl:copy-of select="namespace::*"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   182
		<xsl:for-each select="$other/namespace::*[.!=current()/namespace::*]"><xsl:copy/></xsl:for-each>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   183
		<xsl:for-each select="exslt:node-set($namespaces)/*/namespace::*"><xsl:copy/></xsl:for-each>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   184
	<!-- translate all IDs in downstream doc to use namespaces from upstream doc  
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   185
		This is so much easier than having to propigate this info around while creating the doc-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   186
	<xsl:variable name="otherdoc">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   187
		<xsl:apply-templates mode="translate-namespaces" select="$other">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   188
			<xsl:with-param name="nsdoc" select="exslt:node-set($namespaces)/* | ."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   189
		</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   190
	</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   191
		<xsl:apply-templates mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   192
			<xsl:with-param name="other" select="exslt:node-set($otherdoc)/*"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   193
			<xsl:with-param name="up" select="$up"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   194
			<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   195
		</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   196
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   197
	</xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   198
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   199
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   200
<xsl:template match="systemModel" mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   201
	<xsl:param name="other"/>	<!-- the parent of the downstream systemModel this is merged with -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   202
	<xsl:param name="up"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   203
	<xsl:param name="down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   204
	<xsl:copy><xsl:copy-of  select="@*"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   205
		<!--  copy metas and comments in between meta. Do not try to merge metadata between models -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   206
			<xsl:copy-of select="meta | $other/systemModel/meta | comment()[following-sibling::meta]"/>	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   207
		<xsl:apply-templates mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   208
			<xsl:with-param name="other" select="$other/systemModel"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   209
			<xsl:with-param name="up" select="$up"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   210
			<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   211
		</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   212
	</xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   213
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   214
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   215
<xsl:template match="@*|*|comment()" mode="merge-models"><xsl:copy-of select="."/></xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   216
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   217
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   218
<xsl:template match="meta|comment()[following-sibling::meta]" mode="merge-models"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   219
	<!-- copy elesewhere, not here so that metas always appear first-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   220
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   221
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   222
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   223
<!-- merge levels attribute via std rules -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   224
<xsl:template match="layer/@levels|package/@levels" mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   225
	<xsl:param name="other"/><!-- the element contains the other @levels -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   226
	<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   227
		<!--  if they are the same, or not specified in the other,  just copy -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   228
		<xsl:when test=".=$other/@levels or not($other/@levels)"><xsl:copy-of select="."/></xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   229
		<xsl:when test="contains(concat(' ',normalize-space(.),' '),concat(' ',normalize-space($other/@levels),' '))">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   230
			<!--upstream completely contains downstream, just copy --> 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   231
			<xsl:copy-of select="."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   232
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   233
		<xsl:when test="contains(concat(' ',normalize-space($other/@levels),' '),concat(' ',normalize-space(.),' '))">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   234
			<!--  If this is contained is other, then use other-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   235
			<xsl:copy-of select="$other/@levels"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   236
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   237
		<xsl:when test="contains($other/@levels,'+')">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   238
			<!-- if other uses + syntax, then pre/append -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   239
			<xsl:variable name="lev">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   240
				<xsl:value-of select="substring-before($other/@levels,'+')"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   241
				<xsl:value-of select="concat(' ',.,' ')"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   242
				<xsl:value-of select="substring-after($other/@levels,'+')"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   243
			</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   244
			<xsl:attribute name="levels"><xsl:value-of select="normalize-space($lev)"/></xsl:attribute>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   245
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   246
		<xsl:otherwise> <!--  if they differ, use the origin's levels -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   247
			<xsl:message>Note: levels differ "<xsl:value-of select="."/>" vs "<xsl:value-of select="$other/@levels"/>"</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   248
			<xsl:copy-of select="."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   249
		</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   250
	</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   251
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   252
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   253
<xsl:template name="copy-sorted-content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   254
	<xsl:param name="base"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   255
	<xsl:param name="to-sort"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   256
	<xsl:param name="start"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   257
	<xsl:param name="end"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   258
	<xsl:param name="down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   259
	<xsl:param name="remainder" select="/.."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   260
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   261
	<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   262
		<xsl:when test="not($to-sort)"/>  <!-- nothing left to copy. stop -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   263
		<xsl:when test="not($base)"/>  <!-- reached end. stop -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   264
		<xsl:when test="$base[1]/@id=$end/following-sibling::*[1]/@id"/> <!-- passed $end. Stop -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   265
		<xsl:when test="$base[1]/@id = $to-sort[1]/@id">  <!-- both lists start with same item -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   266
			<xsl:if test="$base[1]/@id!=$end/@id"> <!-- not at end, so keep going -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   267
				<xsl:call-template name="copy-sorted-content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   268
					<xsl:with-param name="base" select="$base[position() != 1]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   269
					<xsl:with-param name="to-sort" select="$to-sort[position() != 1]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   270
					<xsl:with-param name="remainder" select="$remainder"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   271
					<xsl:with-param name="start" select="$start"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   272
					<xsl:with-param name="end" select="$end"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   273
					<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   274
				</xsl:call-template>		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   275
			</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   276
		</xsl:when>	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   277
		<xsl:when test="$remainder[@id = $base[1]/@id]"> <!-- left over item is in $base -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   278
			<xsl:call-template name="copy-sorted-content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   279
				<xsl:with-param name="base" select="$base[position() != 1]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   280
				<xsl:with-param name="to-sort" select="$to-sort"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   281
				<xsl:with-param name="remainder" select="$remainder[@id != $base[1]/@id]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   282
				<xsl:with-param name="start" select="$start"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   283
				<xsl:with-param name="end" select="$end"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   284
				<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   285
			</xsl:call-template>		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   286
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   287
		<xsl:when test="not($base[@id = $to-sort[1]/@id])"> <!-- in to-sort, but not base -->		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   288
			<xsl:if test="$base[1]/@id=$end/@id  and not($base[@id=$to-sort[1]/@before])">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   289
			 	<!-- if at end, then this needs to be copied
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   290
					don't copy if the before ID is found in $base	-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   291
				<xsl:apply-templates mode="merge-copy-of" select="$to-sort[1]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   292
					<xsl:with-param name="origin" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   293
					<xsl:with-param name="root" select="$end/ancestor::systemModel"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   294
				</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   295
			</xsl:if>			
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   296
		<xsl:call-template name="copy-sorted-content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   297
			<xsl:with-param name="base" select="$base"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   298
			<xsl:with-param name="to-sort" select="$to-sort[position() != 1]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   299
			<xsl:with-param name="remainder" select="$remainder"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   300
			<xsl:with-param name="start" select="$start"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   301
			<xsl:with-param name="end" select="$end"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   302
			<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   303
		</xsl:call-template>		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   304
		</xsl:when>	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   305
		<xsl:when test="not($to-sort[@id = $base[1]/@id])"> <!-- in base, but not to-sort -->		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   306
		<xsl:call-template name="copy-sorted-content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   307
			<xsl:with-param name="base" select="$base[position() != 1]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   308
			<xsl:with-param name="to-sort" select="$to-sort"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   309
			<xsl:with-param name="remainder" select="$remainder"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   310
			<xsl:with-param name="start" select="$start"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   311
			<xsl:with-param name="end" select="$end"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   312
			<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   313
		</xsl:call-template>		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   314
		</xsl:when>	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   315
		<xsl:when test="$base[@id = $to-sort[1]/@id]"> <!-- is in base, but not 1st one-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   316
			<xsl:call-template name="copy-sorted-content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   317
				<xsl:with-param name="base" select="$base"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   318
				<xsl:with-param name="to-sort" select="$to-sort[position() != 1] "/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   319
				<xsl:with-param name="remainder" select="$remainder | $to-sort[1]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   320
				<xsl:with-param name="start" select="$start"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   321
				<xsl:with-param name="end" select="$end"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   322
				<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   323
			</xsl:call-template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   324
		</xsl:when>	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   325
	</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   326
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   327
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   328
<xsl:template match="layer | package | collection | component" mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   329
	<xsl:param name="other"/>	<!-- the downstream item of the parent's rank that contains a potential items this is merged with -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   330
	<xsl:param name="up"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   331
	<xsl:param name="down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   332
	<xsl:variable name="this" select="."/>	<!-- current item -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   333
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   334
	<!-- match = this item in the downstream model -->	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   335
	<xsl:variable name="match" select="$other/*[@id=current()/@id]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   336
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   337
	<!-- prev = the previous item before the current one (no metas, only named items)-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   338
	<xsl:variable name="prev" select="preceding-sibling::*[@id][1]"/> 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   339
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   340
	<!-- copy all items between this and prev  that are solely in the downstream model -->	 		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   341
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   342
	<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   343
		<xsl:when test="$match and (not($prev) or $other/*[@id= $prev/@id] )">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   344
			<xsl:call-template name="copy-sorted-content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   345
				<xsl:with-param name="base" select="../*[@id]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   346
				<xsl:with-param name="to-sort" select="$other/*[@id]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   347
				<xsl:with-param name="start" select="$prev"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   348
				<xsl:with-param name="end" select="."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   349
				<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   350
			</xsl:call-template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   351
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   352
	<xsl:when test="not($match/preceding-sibling::*[@id=$this/../*/@id]) and $other/*[@id= current()/@id]/preceding-sibling::*[@id and not(@before)]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   353
		<!-- if this is the first item in other that's also in this, then put all new items from other here -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   354
		<xsl:apply-templates mode="merge-copy-of" select="$match/preceding-sibling::*[@id and not(@before)]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   355
			<xsl:with-param name="origin" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   356
			<xsl:with-param name="root" select="$this/ancestor::systemModel"/>	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   357
		</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   358
	</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   359
	</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   360
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   361
 	<!-- just copy anything identified as being before this, assume they're all ok -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   362
	<xsl:apply-templates mode="merge-copy-of" select="$other/*[@before=current()/@id]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   363
		<xsl:with-param name="remove-before" select="1"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   364
		<xsl:with-param name="origin" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   365
		<xsl:with-param name="root" select="$this/ancestor::systemModel"/>	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   366
	</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   367
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   368
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   369
	<xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   370
		<xsl:apply-templates select="@*" mode="merge-models"> <!-- copy upstream attributes -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   371
			<xsl:with-param name="other" select="$match"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   372
		</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   373
		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   374
		<xsl:if test="self::component and not(@origin-model) and $up/@name">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   375
			<!-- insert origin-model and optional root for components only -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   376
			<xsl:attribute name="origin-model">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   377
				<xsl:value-of select="$up/@name"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   378
			</xsl:attribute>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   379
			<xsl:if test="not(@root)">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   380
				<xsl:copy-of select="$up/@root"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   381
			</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   382
		</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   383
		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   384
		<xsl:for-each select="$match/@*">  <!-- copy downstream attributes, only if not set on upstream -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   385
			<xsl:if test="not($this/@*[name()=name(current())])"><xsl:copy-of select="."/></xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   386
		</xsl:for-each>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   387
		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   388
		<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   389
			<xsl:when test="self::component">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   390
				<!-- copy all units, metas and comments from this
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   391
					copy all metas in the merged component
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   392
					copy any new comments in the merged component (not duplicates)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   393
					if there are no units in the this, copy all units in the merged component
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   394
					if there are units in this, copy only the versioned units in the merged component (only those versions not already specified) -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   395
				<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()]"/>				
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   396
			</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   397
			<xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   398
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   399
				<!--  copy metas and comments in between meta. Do not try to merge metadata between models -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   400
				<xsl:copy-of select="meta | $match/meta | comment()[following-sibling::meta]"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   401
				
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   402
				<xsl:apply-templates mode="merge-models">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   403
					<xsl:with-param name="other" select="$match"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   404
					<xsl:with-param name="up" select="$up"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   405
					<xsl:with-param name="down" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   406
				</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   407
				<!--  don't copy if explicitly or implicitly placed already-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   408
				<xsl:for-each select="$match/*[not(@before) and not(following-sibling::*[@id=$this/*/@id])]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   409
					<xsl:if test="not($this/*[@id=current()/@id])">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   410
						<xsl:apply-templates mode="merge-copy-of" select=".">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   411
							<xsl:with-param name="origin" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   412
							<xsl:with-param name="root" select="$this/ancestor::systemModel"/>			
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   413
						</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   414
					</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   415
				</xsl:for-each>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   416
			</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   417
		</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   418
	</xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   419
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   420
	<xsl:if test="self::layer and not(following-sibling::layer)">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   421
		<!-- for the last layer, tack on any remaining layers -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   422
		<xsl:apply-templates mode="merge-copy-of" select="$other/layer[not(@before) and not(following-sibling::*[@id=$this/../layer/@id]) and not(@id=$this/@id)]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   423
			<xsl:with-param name="origin" select="$down"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   424
			<xsl:with-param name="root" select="$this/ancestor::systemModel"/>			
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   425
		</xsl:apply-templates>		
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   426
	</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   427
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   428
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   429
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   430
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   431
<xsl:template match="*" mode="merge-copy-of">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   432
	<xsl:param name="remove-before" select="0"/> <!-- set to true if any before attribute is to be removed -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   433
	<xsl:param name="origin"/>	<!--the element containing the @name to use the origin-model attribute  -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   434
	<xsl:param name="root"/> 	<!--the systemModel element in the upstream doc  -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   435
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   436
	<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   437
		<!-- this might slow things down, consider making optional -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   438
		<xsl:when test="not(self::layer) and count($root/descendant::*[name()=name(current()/..) and @id!=current()/../@id]/*[@id=current()/@id])">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   439
			<xsl:message>Warning: <xsl:value-of select="name()"/> "<xsl:value-of select="@id"/>" moved in downstream model. Ignoring moved <xsl:value-of select="name()"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   440
				<xsl:text>&#xa;</xsl:text>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   441
			</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   442
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   443
		<xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   444
			<!-- save all content in a variable to test to see if it's got any problems (ie been removed due to errors)-->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   445
			<xsl:variable name="content">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   446
				<xsl:apply-templates select="*|comment()" mode="merge-copy-of">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   447
					<xsl:with-param name="origin" select="$origin"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   448
					<xsl:with-param name="root" select="$root"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   449
				</xsl:apply-templates>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   450
			</xsl:variable>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   451
			<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   452
				<!-- if all elements in this have been deleted, throw out this element -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   453
				<xsl:when test="not(exslt:node-set($content)/*) and *">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   454
					<xsl:message>Warning: All content in downstream <xsl:value-of select="name()"/> "<xsl:value-of select="@id"/>" is invalid. Ignoring <xsl:value-of select="name()"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   455
						<xsl:text>&#xa;</xsl:text>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   456
					</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   457
				</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   458
				<xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   459
					<xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   460
						<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   461
							<xsl:when test="$remove-before">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   462
								<xsl:copy-of select="@*[name()!='before']"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   463
							</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   464
							<xsl:otherwise><xsl:copy-of select="@*"/></xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   465
						</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   466
						<xsl:copy-of select="exslt:node-set($content)"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   467
					</xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   468
				</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   469
			</xsl:choose>					
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   470
		</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   471
	</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   472
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   473
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   474
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   475
<xsl:template match="comment()|@*" mode="merge-copy-of">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   476
	<xsl:copy-of select="."/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   477
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   478
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   479
<xsl:template match="component" mode="merge-copy-of">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   480
	<xsl:param name="remove-before" select="0"/> <!-- set to true if any before attribute is to be removed -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   481
	<xsl:param name="origin"/>	<!--the element containing the @name to use the origin-model attribute  -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   482
	<xsl:param name="root"/> 	<!--the systemModel element in the upstream doc  -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   483
	
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   484
	<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   485
		<!-- this might slow things down, consider making optional -->
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   486
		<xsl:when test="$root/descendant::collection[@id!=current()/../@id]/component[@id=current()/@id]">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   487
			<xsl:message>Warning: <xsl:value-of select="name()"/> "<xsl:value-of select="@id"/>" moved in downstream model. Ignoring moved <xsl:value-of select="name()"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   488
				<xsl:text>&#xa;</xsl:text>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   489
			</xsl:message>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   490
		</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   491
		<xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   492
			<xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   493
				<xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   494
					<xsl:when test="$remove-before">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   495
						<xsl:copy-of select="@*[name()!='before']"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   496
					</xsl:when>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   497
					<xsl:otherwise><xsl:copy-of select="@*"/></xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   498
				</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   499
				<xsl:if test="not(@origin-model) and $origin/@name">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   500
					<xsl:attribute name="origin-model">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   501
						<xsl:value-of select="$origin/@name"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   502
					</xsl:attribute>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   503
					<xsl:if test="not(@root)">
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   504
						<xsl:copy-of select="$origin/@root"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   505
					</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   506
				</xsl:if>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   507
				<xsl:copy-of select="*|comment()"/>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   508
			</xsl:copy>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   509
		</xsl:otherwise>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   510
	</xsl:choose>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   511
</xsl:template>
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   512
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   513
</xsl:stylesheet>