|
1 <?xml version="1.0"?> |
|
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|
3 xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="exslt"> |
|
4 <!-- save SF namespace as a constant to avoid the risk of typos--> |
|
5 <xsl:variable name="defaultns">http://www.symbian.org/system-definition</xsl:variable> |
|
6 |
|
7 <!-- create a stand-alone sysdef from a linked set of fragments --> |
|
8 |
|
9 <xsl:template match="/*" mode="join"> |
|
10 <xsl:message terminate="yes">Cannot process this document</xsl:message> |
|
11 </xsl:template> |
|
12 |
|
13 |
|
14 <xsl:template match="/SystemDefinition[@schema='3.0.0' and count(*)=1]" mode="join"> |
|
15 <xsl:param name="origin" select="/.."/> |
|
16 <xsl:param name="root"/> |
|
17 <xsl:param name="filename"/> |
|
18 <xsl:param name="namespaces"/> |
|
19 <xsl:param name="data" select="/.."/> |
|
20 <xsl:choose> |
|
21 <xsl:when test="$origin"> <!-- this sysdef fragment was linked from a parent sysdef --> |
|
22 <xsl:for-each select="*"> <!-- can be only one --> |
|
23 <xsl:variable name="upid"><xsl:apply-templates select="$origin/@id" mode="my-id"/></xsl:variable> <!-- namespaceless ID of this in parent doc --> |
|
24 <xsl:variable name="id"><xsl:apply-templates select="@id" mode="my-id"/></xsl:variable> <!-- namespaceless ID of this here --> |
|
25 <xsl:variable name="upns"><xsl:apply-templates select="$origin/@id" mode="my-namespace"/></xsl:variable> <!-- ID's namespace in parent doc --> |
|
26 <xsl:variable name="ns"><xsl:apply-templates select="@id" mode="my-namespace"/></xsl:variable> <!-- ID's namespace --> |
|
27 <xsl:if test="$id!=$upid or $ns!=$upns"> |
|
28 <xsl:message terminate="yes">Linked ID "<xsl:value-of select="$id"/>" (<xsl:value-of select="$ns"/>) must match linking document "<xsl:value-of select="$upid"/>" (<xsl:value-of select="$upns"/>)</xsl:message> |
|
29 </xsl:if> |
|
30 <!-- copy any attributes not already defined (parent doc overrides child doc)--> |
|
31 <xsl:for-each select="@*"> |
|
32 <xsl:variable name="n" select="name()"/> |
|
33 <xsl:choose> |
|
34 <xsl:when test="$n='id'"/> <!-- never copy this, always set --> |
|
35 <xsl:when test="$origin/@*[name()=$n]"> <!-- don't copy if already set --> |
|
36 <xsl:message>Cannot set "<xsl:value-of select="$n"/>", already set</xsl:message> |
|
37 </xsl:when> |
|
38 <xsl:when test="$n='before'"> |
|
39 <!-- ensure ns is correct (if any future attribtues will ever use an ID, process it here too)--> |
|
40 <xsl:apply-templates select="." mode="join"> |
|
41 <xsl:with-param name="namespaces" select="$namespaces"/> |
|
42 </xsl:apply-templates> |
|
43 </xsl:when> |
|
44 <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- just copy anything else --> |
|
45 </xsl:choose> |
|
46 </xsl:for-each> |
|
47 <xsl:copy-of select="../namespace::*[not(.=$namespaces)]"/> <!-- set any namespaces not already set (they should all alreayd be, but some XSLT processors are quirky) --> |
|
48 <xsl:apply-templates select="$data" mode="overlay-attributes"> |
|
49 <xsl:with-param name="item" select="current()"/> |
|
50 </xsl:apply-templates> |
|
51 <xsl:variable name="content"> |
|
52 <xsl:apply-templates select="*|comment()" mode="join"> |
|
53 <xsl:with-param name="root" select="$root"/> |
|
54 <xsl:with-param name="filename" select="$filename"/> |
|
55 <xsl:with-param name="data" select="$data"/> |
|
56 <xsl:with-param name="namespaces" select="$namespaces | ../namespace::*[not(.=$namespaces)]"/> |
|
57 </xsl:apply-templates> |
|
58 </xsl:variable> |
|
59 <xsl:apply-templates select="." mode="is-content-filtered"> <!-- optionally add filtered="yes" if some content has been removed --> |
|
60 <xsl:with-param name="content" select="$content"/> |
|
61 </xsl:apply-templates> |
|
62 <xsl:apply-templates select="$data" mode="overlay-meta"> |
|
63 <xsl:with-param name="item" select="current()"/> |
|
64 </xsl:apply-templates> |
|
65 <xsl:copy-of select="$content"/> |
|
66 </xsl:for-each> |
|
67 </xsl:when> |
|
68 <xsl:when test="function-available('exslt:node-set')"> <!-- this is the root element of a root sysdef --> |
|
69 <!--try to put all namespaces in root element --> |
|
70 <xsl:variable name="nss"> |
|
71 <!-- contains node set of namespaces to add to root element. |
|
72 May panic if there are too many single-letter namespaces and this can't create a new one --> |
|
73 <xsl:call-template name="needed-namespaces"> |
|
74 <xsl:with-param name="foundns"> |
|
75 <xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/> |
|
76 </xsl:with-param> |
|
77 </xsl:call-template> |
|
78 </xsl:variable> |
|
79 <xsl:variable name="ns" select="@id-namespace | namespace::* | exslt:node-set($nss)/*"/> |
|
80 <xsl:copy><xsl:copy-of select="@*"/> |
|
81 <xsl:apply-templates select="self::*[not(@id-namespace)]" mode="add-id-ns"/> |
|
82 <xsl:for-each select="exslt:node-set($nss)/*"> <!-- add namespace definitions --> |
|
83 <xsl:attribute name="xmlns:{name()}"> |
|
84 <xsl:value-of select="."/> |
|
85 </xsl:attribute> |
|
86 </xsl:for-each> |
|
87 <!-- no need to call is-content-filtered, it never will be from this element --> |
|
88 <xsl:apply-templates select="*|comment()" mode="join"> |
|
89 <xsl:with-param name="namespaces" select="$ns"/> |
|
90 <xsl:with-param name="root" select="$root"/> |
|
91 <xsl:with-param name="data" select="$data"/> |
|
92 <xsl:with-param name="filename" select="$filename"/> |
|
93 </xsl:apply-templates> |
|
94 </xsl:copy> |
|
95 </xsl:when> |
|
96 <xsl:otherwise> <!-- can't handle node-set() so put the namespaces in the document instead of the root element--> |
|
97 <xsl:variable name="ns" select="@id-namespace | namespace::*"/> |
|
98 <xsl:copy><xsl:copy-of select="@*"/> |
|
99 <!-- no need to call is-content-filtered, it never will be from this element --> |
|
100 <xsl:apply-templates select="*|comment()" mode="join"> |
|
101 <xsl:with-param name="namespaces" select="$ns"/> |
|
102 <xsl:with-param name="root" select="$root"/> |
|
103 <xsl:with-param name="data" select="$data"/> |
|
104 <xsl:with-param name="filename" select="$filename"/> |
|
105 </xsl:apply-templates> |
|
106 </xsl:copy> |
|
107 </xsl:otherwise> |
|
108 </xsl:choose> |
|
109 </xsl:template> |
|
110 |
|
111 <xsl:template match="*" mode="scan-for-namespaces"/> <!-- just in case of errors, consider replacing by terminate --> |
|
112 <xsl:template match="*[@href and not(self::meta)]" mode="scan-for-namespaces"> |
|
113 <!-- produce a list of namespace-prefix namespace pairs separated by newlines, in reverse order found in documents |
|
114 reverse order so we can try to use the first namespace prefix defined if it's available--> |
|
115 <xsl:for-each select="document(@href,.)/*"> |
|
116 <xsl:apply-templates select="//*[(self::component or self::collection or self::package or self::layer) and @href]" mode="scan-for-namespaces"/> |
|
117 <xsl:for-each select="//namespace::* | @id-namespace"> |
|
118 <xsl:value-of select="concat(name(),' ',.,'
')"/> |
|
119 </xsl:for-each> |
|
120 </xsl:for-each> |
|
121 </xsl:template> |
|
122 |
|
123 <xsl:template name="needed-namespaces"> |
|
124 <xsl:param name="foundns"/> |
|
125 <xsl:param name="usedpre"/> |
|
126 |
|
127 <xsl:if test="foundns!=''"> |
|
128 <xsl:variable name="line" select="substring-before($foundns,'
')"/> <!-- always has trailing newline --> |
|
129 <xsl:variable name="name" select="substring-after($line,' ')"/> <!-- namespace prefix --> |
|
130 <xsl:variable name="remainder" select="substring-after($foundns,'
')"/> |
|
131 <xsl:variable name="newprefix"> |
|
132 <xsl:if test="not(contains(concat('
',$remainder),concat('
',$line,'
'))) and |
|
133 not(//namespace::*[.=$name] or @id-namespace[.=$name] or (not(@id-namespace) and $defaultns=$name))"> |
|
134 <xsl:apply-templates select="." mode="ns-prefix"> |
|
135 <xsl:with-param name="ns" select="$name"/> |
|
136 <xsl:with-param name="pre" select="substring-before($line,' ')"/> |
|
137 <xsl:with-param name="dontuse" select="$usedpre"/> |
|
138 </xsl:apply-templates> |
|
139 </xsl:if> |
|
140 </xsl:variable> |
|
141 <xsl:if test="$newprefix!=''"> |
|
142 <!-- can treat this as if it were a namespace node --> |
|
143 <xsl:element name="{$newprefix}"> |
|
144 <xsl:value-of select="$name"/> |
|
145 </xsl:element> |
|
146 </xsl:if> |
|
147 <xsl:if test="$remainder!=''"> |
|
148 <xsl:call-template name="needed-namespaces"> |
|
149 <xsl:with-param name="foundns" select="$remainder"/> |
|
150 <xsl:with-param name="usedpre" select="concat($usedpre,' ',$newprefix,' ')"/> |
|
151 </xsl:call-template> |
|
152 </xsl:if> |
|
153 </xsl:if> |
|
154 </xsl:template> |
|
155 |
|
156 <xsl:template match="/SystemDefinition" mode="ns-prefix"> |
|
157 <!-- should be able to replace this with mechanism that uses the XSLT processor's own ability to generate namespaces --> |
|
158 <xsl:param name="ns"/> |
|
159 <xsl:param name="pre"/> |
|
160 <xsl:param name="dontuse"/> |
|
161 <xsl:param name="chars">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:param> |
|
162 <xsl:variable name="name" select="substring(substring-after($ns,'http://www.'),1,1)"/> |
|
163 <xsl:choose> |
|
164 <xsl:when test="$pre!='' and $pre!='id-namespace' and not(//namespace::*[name()=$pre]) and not(contains($dontuse,concat(' ',$pre,' ')))"> |
|
165 <xsl:value-of select="$pre"/> |
|
166 </xsl:when> |
|
167 <xsl:when test="$ns='' and $chars=''"> |
|
168 <xsl:message terminate="yes">Cannot create namespace prefix for downstream default namespace</xsl:message> |
|
169 </xsl:when> |
|
170 <xsl:when test="$name!='' and not(contains($dontuse,concat(' ',$name,' ')))"><xsl:value-of select="$name"/></xsl:when> |
|
171 <xsl:when test="namespace::*[name()=substring($chars,1,1)] or contains($dontuse,concat(' ',substring($chars,1,1),' '))"> |
|
172 <xsl:apply-templates mode="ns-prefix"> |
|
173 <xsl:with-param name="chars" select="substring($chars,2)"/> |
|
174 </xsl:apply-templates> |
|
175 </xsl:when> |
|
176 <xsl:otherwise> |
|
177 <xsl:value-of select="substring($chars,1,1)"/> |
|
178 </xsl:otherwise> |
|
179 </xsl:choose> |
|
180 </xsl:template> |
|
181 |
|
182 |
|
183 <xsl:template match="unit" mode="join"> <xsl:param name="root"/><xsl:param name="filename"/><xsl:param name="data"/> |
|
184 <xsl:variable name="display"> |
|
185 <xsl:apply-templates select="$data" mode="filter"> |
|
186 <xsl:with-param name="item" select="current()"/> |
|
187 </xsl:apply-templates> |
|
188 </xsl:variable> |
|
189 |
|
190 <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output--> |
|
191 <xsl:element name="{name()}"> |
|
192 <xsl:apply-templates select="@*" mode="join"> |
|
193 <xsl:with-param name="root" select="$root"/> |
|
194 <xsl:with-param name="filename" select="$filename"/> |
|
195 </xsl:apply-templates> |
|
196 </xsl:element> |
|
197 </xsl:if> |
|
198 </xsl:template> |
|
199 |
|
200 <!-- override mode="meta" to translate metadata sections. By default, include --> |
|
201 <xsl:template match="meta" priority="2"><xsl:param name="data"/> |
|
202 <xsl:variable name="display"> |
|
203 <xsl:apply-templates select="$data" mode="filter"> |
|
204 <xsl:with-param name="item" select="current()"/> |
|
205 </xsl:apply-templates> |
|
206 </xsl:variable> |
|
207 |
|
208 <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output--> |
|
209 <xsl:apply-templates select="." mode="meta"> |
|
210 <xsl:with-param name="display" select="$display"/> |
|
211 <xsl:with-param name="data" select="$data"/> |
|
212 </xsl:apply-templates> |
|
213 </xsl:if> |
|
214 </xsl:template> |
|
215 |
|
216 |
|
217 <xsl:template match="*" mode="join"> |
|
218 <xsl:param name="root"/><xsl:param name="filename"/><xsl:param name="namespaces"/><xsl:param name="data"/> |
|
219 <!-- get attribtues from overlay --> |
|
220 <!-- test for presence, if filtered out, just return --> |
|
221 <!-- test for children, if it has some, but they're filtered out, either return or leave as empty, dependening on filter rule |
|
222 if had items and now has none, options: |
|
223 still has meta: keep / delete |
|
224 still has comments: keep / delete |
|
225 --> |
|
226 |
|
227 <xsl:variable name="display"> |
|
228 <xsl:apply-templates select="$data" mode="filter"> |
|
229 <xsl:with-param name="item" select="current()"/> |
|
230 </xsl:apply-templates> |
|
231 </xsl:variable> |
|
232 |
|
233 <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output--> |
|
234 |
|
235 <xsl:variable name="href"> |
|
236 <xsl:apply-templates select="." mode="link"> |
|
237 <xsl:with-param name="data" select="$data"/> |
|
238 </xsl:apply-templates> |
|
239 </xsl:variable> |
|
240 |
|
241 |
|
242 <xsl:element name="{name()}"> <!-- use this instead of <copy> so xalan doesn't add extra wrong namespaces --> |
|
243 <xsl:apply-templates select="@*" mode="join"> |
|
244 <xsl:with-param name="namespaces" select="$namespaces"/> |
|
245 </xsl:apply-templates> |
|
246 <xsl:if test="$display != '' "> |
|
247 <!-- custom attribute to indicate how this is to be represented. Blank indicates normal, hide removes from the output (see above), anything else is put in the attribute --> |
|
248 <xsl:attribute name="display"><xsl:value-of select="$display"/></xsl:attribute> |
|
249 </xsl:if> |
|
250 <xsl:apply-templates select="$data" mode="overlay-attributes"> |
|
251 <xsl:with-param name="item" select="current()"/> |
|
252 </xsl:apply-templates> |
|
253 <xsl:choose> |
|
254 <xsl:when test="$href !='' "> |
|
255 <xsl:variable name="origin" select="."/> |
|
256 <xsl:apply-templates select="document($href,.)/*" mode="join"> |
|
257 <xsl:with-param name="origin" select="$origin"/> |
|
258 <xsl:with-param name="data" select="$data"/> |
|
259 <xsl:with-param name="namespaces" select="$namespaces"/> |
|
260 <xsl:with-param name="filename"> |
|
261 <xsl:call-template name="joinpath"> |
|
262 <xsl:with-param name="file" select="$filename"/> |
|
263 <xsl:with-param name="rel" select="$href"/> |
|
264 </xsl:call-template> |
|
265 </xsl:with-param> |
|
266 <xsl:with-param name="root"> |
|
267 <xsl:value-of select="$root"/>/<xsl:call-template name="lastbefore"> |
|
268 <xsl:with-param name="string" select="$href"/> |
|
269 </xsl:call-template> |
|
270 </xsl:with-param> |
|
271 </xsl:apply-templates> |
|
272 </xsl:when> |
|
273 <xsl:otherwise> |
|
274 <xsl:variable name="content"> |
|
275 <xsl:apply-templates select="*|comment()" mode="join"> |
|
276 <xsl:with-param name="root" select="$root"/> |
|
277 <xsl:with-param name="filename" select="$filename"/> |
|
278 <xsl:with-param name="namespaces" select="$namespaces"/> |
|
279 <xsl:with-param name="data" select="$data"/> |
|
280 </xsl:apply-templates> |
|
281 </xsl:variable> |
|
282 <xsl:apply-templates select="." mode="is-content-filtered"> <!-- add filtered="yes" if some content has been removed --> |
|
283 <xsl:with-param name="content" select="$content"/> |
|
284 </xsl:apply-templates> |
|
285 <xsl:apply-templates select="$data" mode="overlay-meta"> |
|
286 <xsl:with-param name="item" select="current()"/> |
|
287 </xsl:apply-templates> |
|
288 <xsl:copy-of select="$content"/> |
|
289 </xsl:otherwise> |
|
290 </xsl:choose> |
|
291 </xsl:element> |
|
292 </xsl:if> |
|
293 </xsl:template> |
|
294 |
|
295 <!-- By default, do nothing. Can override template to add filtered="yes" if need to track what's a placeholder and what's been filtered |
|
296 implement with param name="content" |
|
297 --> |
|
298 <xsl:template mode="is-content-filtered" match="*" priority="-2"/> |
|
299 |
|
300 |
|
301 <xsl:template match="@mrp[starts-with(.,'/')] | @bldFile[starts-with(.,'/')] | @base[starts-with(.,'/')]" mode="join"> |
|
302 <xsl:copy-of select="."/> |
|
303 </xsl:template> |
|
304 |
|
305 <xsl:template match="@mrp|@bldFile|@base" mode="join"> <xsl:param name="root"/><xsl:param name="filename"/> |
|
306 <xsl:attribute name="{name()}"> |
|
307 <xsl:call-template name="joinpath"> |
|
308 <xsl:with-param name="file" select="$filename"/> |
|
309 <xsl:with-param name="rel" select="."/> |
|
310 </xsl:call-template> |
|
311 </xsl:attribute> |
|
312 </xsl:template> |
|
313 |
|
314 |
|
315 <xsl:template match="@href" mode="join"/> <!--never copy this into the generated doc, that's the whole point of this module --> |
|
316 |
|
317 <xsl:template match="@*" mode="my-namespace"> <!-- the namespace of an ID --> |
|
318 <xsl:choose> |
|
319 <xsl:when test="contains(.,':')"> |
|
320 <xsl:value-of select="ancestor::*/namespace::*[name()=substring-before(current(),':')]"/> |
|
321 </xsl:when> |
|
322 <xsl:when test="/SystemDefinition/@id-namespace"> |
|
323 <xsl:value-of select="/SystemDefinition/@id-namespace"/> |
|
324 </xsl:when> |
|
325 <xsl:otherwise> |
|
326 <xsl:value-of select="$defaultns"/> |
|
327 </xsl:otherwise> |
|
328 </xsl:choose> |
|
329 </xsl:template> |
|
330 |
|
331 |
|
332 <xsl:template match="@*" mode="my-id"> <!-- the ID with namespace prefix removed --> |
|
333 <xsl:choose> |
|
334 <xsl:when test="contains(.,':')"> |
|
335 <xsl:value-of select="substring-after(.,':')"/> |
|
336 </xsl:when> |
|
337 <xsl:otherwise> |
|
338 <xsl:value-of select="."/> |
|
339 </xsl:otherwise> |
|
340 </xsl:choose> |
|
341 </xsl:template> |
|
342 |
|
343 <xsl:template match="@id|@before" mode="join"> |
|
344 <xsl:param name="namespaces"/> |
|
345 <!-- this will change the namespace prefixes for all IDs to match the root document --> |
|
346 <xsl:variable name="ns"> |
|
347 <xsl:apply-templates select="." mode="my-namespace"/> |
|
348 </xsl:variable> |
|
349 <xsl:if test="$ns=''"> |
|
350 <xsl:message terminate="yes">Could not find namespace for <xsl:value-of select="."/> |
|
351 </xsl:message> |
|
352 </xsl:if> |
|
353 <xsl:variable name="prefix" select="name($namespaces[.=$ns])"/> |
|
354 <xsl:attribute name="{name()}"> |
|
355 <xsl:choose> |
|
356 <xsl:when test="$prefix = 'id-namespace' or (not($namespaces[name()='id-prefix']) and $ns=$defaultns)"/> <!-- it's the default namespace, no prefix --> |
|
357 <xsl:when test="$prefix='' and contains(.,':')"> |
|
358 <!-- complex: copy id and copy namespace (namespace should be copied already)--> |
|
359 <xsl:value-of select="."/> |
|
360 </xsl:when> |
|
361 <xsl:when test="$prefix='' and $ns=$defaultns"/> <!-- no prefix and it's the default --> |
|
362 <xsl:when test="$prefix!=''"> <!-- just change the prefix --> |
|
363 <xsl:value-of select="concat($prefix,':')"/> |
|
364 </xsl:when> |
|
365 <xsl:otherwise> |
|
366 <xsl:message terminate="yes">Error</xsl:message> |
|
367 </xsl:otherwise> |
|
368 </xsl:choose> |
|
369 <xsl:apply-templates select="." mode="my-id"/> |
|
370 </xsl:attribute> |
|
371 </xsl:template> |
|
372 |
|
373 |
|
374 |
|
375 <xsl:template match="@*|comment()" mode="join"><xsl:copy-of select="."/></xsl:template> |
|
376 |
|
377 |
|
378 <!-- path handling follows --> |
|
379 |
|
380 <xsl:template name="lastbefore"><xsl:param name="string"/><xsl:param name="substr" select="'/'"/> |
|
381 <xsl:if test="contains($string,$substr)"> |
|
382 <xsl:value-of select="substring-before($string,$substr)"/> |
|
383 <xsl:if test="contains(substring-after($string,$substr),$substr)"> |
|
384 <xsl:value-of select="$substr"/> |
|
385 </xsl:if> |
|
386 <xsl:call-template name="lastbefore"> |
|
387 <xsl:with-param name="string" select="substring-after($string,$substr)"/> |
|
388 <xsl:with-param name="substr" select="$substr"/> |
|
389 </xsl:call-template> |
|
390 </xsl:if> |
|
391 </xsl:template> |
|
392 |
|
393 <xsl:template name="joinpath"><xsl:param name="file"/><xsl:param name="rel"/> |
|
394 <xsl:call-template name="reducepath"> |
|
395 <xsl:with-param name="file"> |
|
396 <xsl:call-template name="lastbefore"> |
|
397 <xsl:with-param name="string" select="$file"/> |
|
398 </xsl:call-template> |
|
399 <xsl:text>/</xsl:text> |
|
400 <xsl:value-of select="$rel"/> |
|
401 </xsl:with-param> |
|
402 </xsl:call-template> |
|
403 </xsl:template> |
|
404 |
|
405 <xsl:template name="reducepath"><xsl:param name="file"/> |
|
406 <xsl:call-template name="reducedotdotpath"> |
|
407 <xsl:with-param name="file"> |
|
408 <xsl:call-template name="reducedotpath"> |
|
409 <xsl:with-param name="file" select="$file"/> |
|
410 </xsl:call-template> |
|
411 </xsl:with-param> |
|
412 </xsl:call-template> |
|
413 </xsl:template> |
|
414 |
|
415 <xsl:template name="reducedotdotpath"><xsl:param name="file"/> |
|
416 <xsl:choose> |
|
417 <xsl:when test="starts-with($file,'../')"> |
|
418 <xsl:text>../</xsl:text> |
|
419 <xsl:call-template name="reducedotdotpath"> |
|
420 <xsl:with-param name="file" select="substring($file,4)"/> |
|
421 </xsl:call-template> |
|
422 </xsl:when> |
|
423 <xsl:when test="contains($file,'/../')"> |
|
424 <xsl:call-template name="reducepath"> |
|
425 <xsl:with-param name="file"> |
|
426 <xsl:call-template name="lastbefore"> |
|
427 <xsl:with-param name="string" select="substring-before($file,'/../')"/> |
|
428 </xsl:call-template> |
|
429 <xsl:text>/</xsl:text> |
|
430 <xsl:value-of select="substring-after($file,'/../')"/> |
|
431 </xsl:with-param> |
|
432 </xsl:call-template> |
|
433 </xsl:when> |
|
434 <xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise> |
|
435 </xsl:choose> |
|
436 </xsl:template> |
|
437 |
|
438 <xsl:template name="reducedotpath"><xsl:param name="file"/> |
|
439 <xsl:choose> |
|
440 <xsl:when test="starts-with($file,'./')"> |
|
441 <xsl:call-template name="reducedotpath"> |
|
442 <xsl:with-param name="file" select="substring($file,3)"/> |
|
443 </xsl:call-template> |
|
444 </xsl:when> |
|
445 <xsl:when test="contains($file,'/./')"> |
|
446 <xsl:call-template name="reducepath"> |
|
447 <xsl:with-param name="file"> |
|
448 <xsl:value-of select="substring-before($file,'/./')"/> |
|
449 <xsl:text>/</xsl:text> |
|
450 <xsl:value-of select="substring-after($file,'/./')"/> |
|
451 </xsl:with-param> |
|
452 </xsl:call-template> |
|
453 </xsl:when> |
|
454 <xsl:otherwise><xsl:value-of select="$file"/></xsl:otherwise> |
|
455 </xsl:choose> |
|
456 </xsl:template> |
|
457 |
|
458 <!-- overridable templates follow --> |
|
459 |
|
460 |
|
461 <xsl:template match="*" mode="filter" priority="-9"/> <!-- by default show --> |
|
462 <xsl:template match="*" mode="overlay-attributes" priority="-9"/> <!-- by default do nothing --> |
|
463 <xsl:template match="*" mode="overlay-meta" priority="-9"/> <!-- by default do nothing --> |
|
464 <xsl:template match="/SystemDefinition" mode="add-id-ns" priority="-9"/> <!-- some tools may have an easier job if this were always present, but, by default, assume it can just stay implied --> |
|
465 |
|
466 <xsl:template match="*" mode="link" priority="-1"> <!-- can be overriden to allow custom changes to href values --> |
|
467 <xsl:value-of select="@href"/> |
|
468 </xsl:template> |
|
469 |
|
470 |
|
471 <xsl:template match="*" mode="meta" priority="-9"><xsl:param name="data"/><xsl:param name="display"/> |
|
472 <xsl:element name="{name()}"> |
|
473 <xsl:copy-of select="@*[name()!='href']"/> <!-- copy all attributes as is, always drop href --> |
|
474 <xsl:choose> |
|
475 <xsl:when test="$display='local' and @href and contains(@href,':') and not(starts-with(@href,'file:'))"> |
|
476 <!-- non-local URL: only want local URLs, so keep href as is--> |
|
477 <xsl:copy-of select="@href"/> |
|
478 </xsl:when> |
|
479 <xsl:when test="@href"> |
|
480 <xsl:copy-of select="document(@href,.)/*"/> |
|
481 </xsl:when> |
|
482 <xsl:otherwise> |
|
483 <xsl:copy-of select="*|comment()"/> |
|
484 </xsl:otherwise> |
|
485 </xsl:choose> |
|
486 </xsl:element> |
|
487 </xsl:template> |
|
488 |
|
489 </xsl:stylesheet> |