|
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). |
|
3 All rights reserved. |
|
4 This component and the accompanying materials are made available |
|
5 under the terms of the License "Eclipse Public License v1.0" |
|
6 which accompanies this distribution, and is available |
|
7 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
|
9 Initial Contributors: |
|
10 Nokia Corporation - initial contribution. |
|
11 Contributors: |
|
12 Description: |
|
13 Merge two 3.x syntax system definitions |
|
14 --> |
|
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 |
|
26 <xsl:output method="xml" indent="yes"/> |
|
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). --> |
|
28 <xsl:key name="origin" match="component" use="@origin-model"/> |
|
29 |
|
30 <xsl:variable name="downstream" select="document($Downstream,.)/SystemDefinition"/> |
|
31 <xsl:param name="upname"> |
|
32 <xsl:choose> |
|
33 <xsl:when test="$downstream[starts-with(@schema,'2.') or starts-with(@schema,'1.')]"> |
|
34 <xsl:message terminate="yes">Syntax <xsl:value-of select="@schema"/> not supported</xsl:message> |
|
35 </xsl:when> |
|
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)"> |
|
43 <xsl:apply-templates mode="origin-term" select="/*"> |
|
44 <xsl:with-param name="root">Upstream</xsl:with-param> |
|
45 </xsl:apply-templates> |
|
46 </xsl:when> |
|
47 <xsl:otherwise><xsl:value-of select="/SystemDefinition/systemModel/@name"/></xsl:otherwise> |
|
48 </xsl:choose> |
|
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"--> |
|
51 |
|
52 <xsl:param name="downname"> |
|
53 <xsl:choose> |
|
54 <xsl:when test="/SystemDefinition/systemModel/@name=$downstream/systemModel/@name or not($downstream/systemModel/@name)"> |
|
55 <xsl:apply-templates mode="origin-term" select="$downstream"> |
|
56 <xsl:with-param name="root">Downstream</xsl:with-param> |
|
57 </xsl:apply-templates> |
|
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> |
|
62 <xsl:otherwise><xsl:value-of select="$downstream/systemModel/@name"/></xsl:otherwise> |
|
63 </xsl:choose> |
|
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"--> |
|
66 |
|
67 <xsl:template mode="origin-term" match="*"> |
|
68 <xsl:param name="root"/> |
|
69 <xsl:param name="index"/> |
|
70 <xsl:choose> |
|
71 <xsl:when test="not(key('origin',concat($root,$index)))"> |
|
72 <xsl:value-of select="concat($root,$index)"/> |
|
73 </xsl:when> |
|
74 <xsl:when test="$index=''"> |
|
75 <xsl:apply-templates mode="origin-term" select="."> |
|
76 <xsl:with-param name="root" select="$root"/> |
|
77 <xsl:with-param name="index" select="1"/> |
|
78 </xsl:apply-templates> |
|
79 </xsl:when> |
|
80 <xsl:otherwise> |
|
81 <xsl:apply-templates mode="origin-term" select="."> |
|
82 <xsl:with-param name="root" select="$root"/> |
|
83 <xsl:with-param name="index" select="$index + 1"/> |
|
84 </xsl:apply-templates> |
|
85 </xsl:otherwise> |
|
86 </xsl:choose> |
|
87 </xsl:template> |
|
88 |
|
89 |
|
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,'.') > substring-before($v2,'.')"><xsl:value-of select="$v1"/></xsl:when> |
|
95 <xsl:when test="substring-before($v1,'.') < substring-before($v2,'.')"><xsl:value-of select="$v2"/></xsl:when> |
|
96 <xsl:when test="substring-before(substring-after($v1,'.'),'.') > substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when> |
|
97 <xsl:when test="substring-before(substring-after($v1,'.'),'.') < substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v2"/></xsl:when> |
|
98 <xsl:when test="substring-after(substring-after($v1,'.'),'.') > substring-after(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when> |
|
99 <xsl:when test="substring-after(substring-after($v1,'.'),'.') < 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 --> |
|
105 |
|
106 |
|
107 |
|
108 <xsl:template match="/*"> |
|
109 <xsl:variable name="upmodel"> |
|
110 <sysdef name="{$upname}"/> |
|
111 </xsl:variable> |
|
112 <xsl:variable name="downmodel"> |
|
113 <sysdef name="{$downname}" pathto="{$Downstream}"/> |
|
114 </xsl:variable> |
|
115 |
|
116 <xsl:choose> |
|
117 <xsl:when test="function-available('exslt:node-set')"> |
|
118 <xsl:apply-templates mode="merge-models" select="."> |
|
119 <xsl:with-param name="other" select="$downstream"/> |
|
120 <xsl:with-param name="up" select="exslt:node-set($upmodel)/sysdef"/> |
|
121 <xsl:with-param name="down" select="exslt:node-set($downmodel)/sysdef"/> |
|
122 </xsl:apply-templates> |
|
123 </xsl:when> |
|
124 <xsl:otherwise> <!-- no node set funcion, so don't bother setting the names --> |
|
125 <xsl:apply-templates mode="merge-models" select="."> |
|
126 <xsl:with-param name="other" select="$downstream"/> |
|
127 </xsl:apply-templates> |
|
128 </xsl:otherwise> |
|
129 </xsl:choose> |
|
130 </xsl:template> |
|
131 |
|
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 bug 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 |
|
142 </xsl:stylesheet> |