21 |
21 |
22 <xsl:template match="/*" mode="join"> |
22 <xsl:template match="/*" mode="join"> |
23 <xsl:message terminate="yes">ERROR: Cannot process this document</xsl:message> |
23 <xsl:message terminate="yes">ERROR: Cannot process this document</xsl:message> |
24 </xsl:template> |
24 </xsl:template> |
25 |
25 |
26 |
26 <!-- anything in schemas 3.0.x won't add new functional attributes that need processing here, just blindly copy them--> |
27 <xsl:template match="/SystemDefinition[@schema='3.0.0' and count(*)=1]" mode="join"> |
27 |
|
28 <xsl:template match="/SystemDefinition[starts-with(@schema,'3.0.') and count(*)=1]" mode="join"> |
28 <xsl:param name="origin" select="/.."/> |
29 <xsl:param name="origin" select="/.."/> |
29 <xsl:param name="root"/> |
30 <xsl:param name="root"/> |
30 <xsl:param name="filename"/> |
31 <xsl:param name="filename"/> |
31 <xsl:param name="namespaces"/> |
32 <xsl:param name="namespaces"/> |
32 <xsl:param name="data" select="/.."/> |
33 <xsl:param name="data" select="/.."/> |
46 <xsl:choose> |
47 <xsl:choose> |
47 <xsl:when test="$n='id'"/> <!-- never copy this, always set --> |
48 <xsl:when test="$n='id'"/> <!-- never copy this, always set --> |
48 <xsl:when test="$origin/@*[name()=$n]"> <!-- don't copy if already set --> |
49 <xsl:when test="$origin/@*[name()=$n]"> <!-- don't copy if already set --> |
49 <xsl:message>Cannot set "<xsl:value-of select="$n"/>", already set</xsl:message> |
50 <xsl:message>Cannot set "<xsl:value-of select="$n"/>", already set</xsl:message> |
50 </xsl:when> |
51 </xsl:when> |
51 <xsl:when test="$n='before'"> |
52 <xsl:when test="$n='before' or $n='replace'"> |
52 <!-- ensure ns is correct (if any future attribtues will ever use an ID, process it here too)--> |
53 <!-- ensure ns is correct (if any future attribtues will ever use an ID, process it here too)--> |
53 <xsl:apply-templates select="." mode="join"> |
54 <xsl:apply-templates select="." mode="join"> |
54 <xsl:with-param name="namespaces" select="$namespaces"/> |
55 <xsl:with-param name="namespaces" select="$namespaces"/> |
55 </xsl:apply-templates> |
56 </xsl:apply-templates> |
56 </xsl:when> |
57 </xsl:when> |
88 <xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/> |
89 <xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/> |
89 </xsl:with-param> |
90 </xsl:with-param> |
90 </xsl:call-template> |
91 </xsl:call-template> |
91 </xsl:variable> |
92 </xsl:variable> |
92 <xsl:variable name="ns" select="@id-namespace | namespace::* | exslt:node-set($nss)/*"/> |
93 <xsl:variable name="ns" select="@id-namespace | namespace::* | exslt:node-set($nss)/*"/> |
93 <xsl:copy><xsl:copy-of select="@*"/> |
94 <xsl:copy><xsl:copy-of select="@*[name()!='schema']"/><xsl:call-template name="set-schema"/> |
94 <xsl:apply-templates select="self::*[not(@id-namespace)]" mode="add-id-ns"/> |
95 <xsl:apply-templates select="self::*[not(@id-namespace)]" mode="add-id-ns"/> |
95 <xsl:for-each select="exslt:node-set($nss)/*"> <!-- add namespace definitions --> |
96 <xsl:for-each select="exslt:node-set($nss)/*"> <!-- add namespace definitions --> |
96 <xsl:attribute name="xmlns:{name()}"> |
97 <xsl:attribute name="xmlns:{name()}"> |
97 <xsl:value-of select="."/> |
98 <xsl:value-of select="."/> |
98 </xsl:attribute> |
99 </xsl:attribute> |
106 </xsl:apply-templates> |
107 </xsl:apply-templates> |
107 </xsl:copy> |
108 </xsl:copy> |
108 </xsl:when> |
109 </xsl:when> |
109 <xsl:otherwise> <!-- can't handle node-set() so put the namespaces in the document instead of the root element--> |
110 <xsl:otherwise> <!-- can't handle node-set() so put the namespaces in the document instead of the root element--> |
110 <xsl:variable name="ns" select="@id-namespace | namespace::*"/> |
111 <xsl:variable name="ns" select="@id-namespace | namespace::*"/> |
111 <xsl:copy><xsl:copy-of select="@*"/> |
112 <xsl:copy><xsl:copy-of select="@*[name()!='schema']"/><xsl:call-template name="set-schema"/> |
112 <!-- no need to call is-content-filtered, it never will be from this element --> |
113 <!-- no need to call is-content-filtered, it never will be from this element --> |
113 <xsl:apply-templates select="*|comment()" mode="join"> |
114 <xsl:apply-templates select="*|comment()" mode="join"> |
114 <xsl:with-param name="namespaces" select="$ns"/> |
115 <xsl:with-param name="namespaces" select="$ns"/> |
115 <xsl:with-param name="root" select="$root"/> |
116 <xsl:with-param name="root" select="$root"/> |
116 <xsl:with-param name="data" select="$data"/> |
117 <xsl:with-param name="data" select="$data"/> |
186 <xsl:with-param name="chars" select="substring($chars,2)"/> |
187 <xsl:with-param name="chars" select="substring($chars,2)"/> |
187 </xsl:apply-templates> |
188 </xsl:apply-templates> |
188 </xsl:when> |
189 </xsl:when> |
189 <xsl:otherwise> |
190 <xsl:otherwise> |
190 <xsl:value-of select="substring($chars,1,1)"/> |
191 <xsl:value-of select="substring($chars,1,1)"/> |
|
192 </xsl:otherwise> |
|
193 </xsl:choose> |
|
194 </xsl:template> |
|
195 |
|
196 |
|
197 <!-- schema handling --> |
|
198 |
|
199 <xsl:template name="set-schema"> |
|
200 <xsl:attribute name="schema"> |
|
201 <xsl:apply-templates mode="my-schema" select="/SystemDefinition"/> |
|
202 </xsl:attribute> |
|
203 </xsl:template> |
|
204 |
|
205 <xsl:template name="compare-versions"><xsl:param name="v1"/><xsl:param name="v2"/> |
|
206 <xsl:choose> |
|
207 <xsl:when test="$v1=$v2"><xsl:value-of select="$v1"/></xsl:when> |
|
208 <xsl:when test="substring-before($v1,'.') > substring-before($v2,'.')"><xsl:value-of select="$v1"/></xsl:when> |
|
209 <xsl:when test="substring-before($v1,'.') < substring-before($v2,'.')"><xsl:value-of select="$v2"/></xsl:when> |
|
210 <xsl:when test="substring-before(substring-after($v1,'.'),'.') > substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when> |
|
211 <xsl:when test="substring-before(substring-after($v1,'.'),'.') < substring-before(substring-after($v2,'.'),'.')"><xsl:value-of select="$v2"/></xsl:when> |
|
212 <xsl:when test="substring-after(substring-after($v1,'.'),'.') > substring-after(substring-after($v2,'.'),'.')"><xsl:value-of select="$v1"/></xsl:when> |
|
213 <xsl:when test="substring-after(substring-after($v1,'.'),'.') < substring-after(substring-after($v2,'.'),'.')"><xsl:value-of select="$v2"/></xsl:when> |
|
214 <xsl:otherwise><xsl:value-of select="$v1"/></xsl:otherwise> |
|
215 </xsl:choose> |
|
216 </xsl:template> |
|
217 |
|
218 <xsl:template name="compare-version-list"><xsl:param name="list"/> |
|
219 <xsl:variable name="cur" select="substring-before($list,' ')"/> |
|
220 <xsl:variable name="remaining" select="substring-after($list,' ')"/> |
|
221 <xsl:choose> |
|
222 <xsl:when test="$remaining=''"><xsl:value-of select="$cur"/></xsl:when> |
|
223 <xsl:otherwise> |
|
224 <xsl:variable name="nextbig"> |
|
225 <xsl:call-template name="compare-version-list"> |
|
226 <xsl:with-param name="list" select="$remaining"/> |
|
227 </xsl:call-template> |
|
228 </xsl:variable> |
|
229 <xsl:call-template name="compare-versions"> |
|
230 <xsl:with-param name="v1" select="$cur"/> |
|
231 <xsl:with-param name="v2" select="$nextbig"/> |
|
232 </xsl:call-template> |
|
233 </xsl:otherwise> |
|
234 </xsl:choose> |
|
235 </xsl:template> |
|
236 |
|
237 <xsl:template match="/SystemDefinition" mode="my-schema"><xsl:param name="biggest" select="@schema"/> |
|
238 <xsl:variable name="linked" select="//*[(self::component or self::collection or self::package or self::layer) and @href]"/> |
|
239 <xsl:choose> |
|
240 <xsl:when test="not($linked)"> <!-- no need to go further --> |
|
241 <xsl:call-template name="compare-versions"> |
|
242 <xsl:with-param name="v1" select="@schema"/> |
|
243 <xsl:with-param name="v2" select="$biggest"/> |
|
244 </xsl:call-template> |
|
245 </xsl:when> |
|
246 <xsl:otherwise> |
|
247 <xsl:call-template name="compare-version-list"> |
|
248 <xsl:with-param name="list"> |
|
249 <xsl:for-each select="$linked"> |
|
250 <xsl:call-template name="compare-versions"> |
|
251 <xsl:with-param name="v1"> |
|
252 <xsl:apply-templates mode="my-schema" select="document(@href,.)/*"/> |
|
253 </xsl:with-param> |
|
254 <xsl:with-param name="v2" select="$biggest"/> |
|
255 </xsl:call-template> |
|
256 <xsl:text> </xsl:text> |
|
257 </xsl:for-each> |
|
258 </xsl:with-param> |
|
259 </xsl:call-template> |
191 </xsl:otherwise> |
260 </xsl:otherwise> |
192 </xsl:choose> |
261 </xsl:choose> |
193 </xsl:template> |
262 </xsl:template> |
194 |
263 |
195 |
264 |
369 <xsl:apply-templates select=".." mode="err-path"/>/</xsl:if> |
438 <xsl:apply-templates select=".." mode="err-path"/>/</xsl:if> |
370 <xsl:value-of select="@id"/> |
439 <xsl:value-of select="@id"/> |
371 </xsl:template> |
440 </xsl:template> |
372 |
441 |
373 |
442 |
374 <xsl:template match="@id|@before" mode="join"> |
443 <xsl:template match="@id|@before|@replace" mode="join"> |
375 <xsl:param name="namespaces"/> |
444 <xsl:param name="namespaces"/> |
376 <!-- this will change the namespace prefixes for all IDs to match the root document --> |
445 <!-- this will change the namespace prefixes for all IDs to match the root document --> |
377 <xsl:variable name="ns"> |
446 <xsl:variable name="ns"> |
378 <xsl:apply-templates select="." mode="my-namespace"/> |
447 <xsl:apply-templates select="." mode="my-namespace"/> |
379 </xsl:variable> |
448 </xsl:variable> |