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