]> git.saurik.com Git - wxWidgets.git/blob - build/buildbot/tools/embedded.xsl
non-pch build fix
[wxWidgets.git] / build / buildbot / tools / embedded.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!--
4 Name: embedded.xsl
5 Purpose: Embedded XSLT
6 Author: Mike Wetherell
7 RCS-ID: $Id$
8 Copyright: (c) 2007 Mike Wetherell
9 Licence: wxWidgets licence
10 -->
11
12 <transform xmlns="http://www.w3.org/1999/XSL/Transform"
13 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
14 xmlns:XSL="XSL"
15 version="1.0">
16
17 <namespace-alias stylesheet-prefix="XSL" result-prefix="xsl"/>
18
19 <output indent="yes"/>
20
21 <variable
22 name="root"
23 select="//*[not(ancestor-or-self::*[name() != name(/*)])]"/>
24
25 <variable
26 name="includes"
27 select="$root[position() > 1]"/>
28
29 <variable
30 xmlns:func="http://exslt.org/functions"
31 name="top-level"
32 select="$root/xsl:import |
33 $root/xsl:include |
34 $root/xsl:attribute-set |
35 $root/xsl:character-map |
36 $root/xsl:decimal-format |
37 $root/xsl:function |
38 $root/xsl:import-schema |
39 $root/xsl:key |
40 $root/xsl:namespace-alias |
41 $root/xsl:output |
42 $root/xsl:param |
43 $root/xsl:preserve-space |
44 $root/xsl:strip-space |
45 $root/xsl:template |
46 $root/xsl:variable |
47 $root/func:function"/>
48
49 <template match="/">
50 <XSL:transform>
51 <copy-of select="$root/namespace::*"/>
52
53 <for-each select="$root/@xsl:*">
54 <attribute name="{local-name()}">
55 <value-of select="."/>
56 </attribute>
57 </for-each>
58
59 <for-each select="$top-level">
60 <if test="not(../ancestor::*/*[name() = name(current()) and @name = current()/@name])">
61 <apply-templates mode="copy-xsl" select="."/>
62 </if>
63 </for-each>
64
65 <apply-templates select="*"/>
66 </XSL:transform>
67 </template>
68
69 <template match="*">
70 <variable name="pattern">
71 <call-template name="coord-pattern"/>
72 </variable>
73
74 <variable name="is-xsl">
75 <call-template name="is-xsl"/>
76 </variable>
77
78 <XSL:template match="*[generate-id() = generate-id(document('', /){$pattern})]">
79 <copy-of select="namespace::*"/>
80 <choose>
81 <when test="$root/xsl:template[@name = name(current())]">
82 <call-template name="expand">
83 <with-param name="inside-xsl" select="$is-xsl = 'true'"/>
84 </call-template>
85 </when>
86 <when test="count($includes | .) = count($includes)">
87 <if test="node()">
88 <XSL:apply-templates select="node()"/>
89 </if>
90 </when>
91 <when test="count($top-level | .) != count($top-level)">
92 <call-template name="create-context"/>
93 </when>
94 </choose>
95 </XSL:template>
96
97 <if test="$is-xsl != 'true'">
98 <apply-templates select="node()"/>
99 </if>
100 </template>
101
102 <template match="text()"/>
103
104 <template match="@*">
105 <copy/>
106 </template>
107
108 <template mode="copy-xsl" match="*[//xsl:template[not(ancestor::*[name() != name(/*)])]/@name = name()]">
109 <choose>
110 <when test="ancestor::xsl:template[@name = name(current())]">
111 <XSL:choose>
112 <XSL:when test="name() = '{name()}'">
113 <XSL:copy>
114 <call-template name="copy-xsl-children"/>
115 </XSL:copy>
116 </XSL:when>
117 <XSL:otherwise>
118 <copy>
119 <call-template name="copy-xsl-children"/>
120 </copy>
121 </XSL:otherwise>
122 </XSL:choose>
123 </when>
124 <otherwise>
125 <call-template name="expand">
126 <with-param name="inside-xsl" select="true()"/>
127 </call-template>
128 </otherwise>
129 </choose>
130 </template>
131
132 <template mode="copy-xsl" match="@*|node()">
133 <copy>
134 <call-template name="copy-xsl-children"/>
135 </copy>
136 </template>
137
138 <template name="copy-xsl-children">
139 <copy-of select="namespace::*"/>
140 <apply-templates mode="copy-xsl" select="@*|node()"/>
141 </template>
142
143 <template name="coord-pattern">
144 <param name="element" select="."/>
145
146 <for-each select="$element/ancestor-or-self::*">
147 <text>/*[</text>
148 <value-of select="count(preceding-sibling::*) + 1"/>
149 <text>]</text>
150 </for-each>
151 </template>
152
153 <template name="is-xsl">
154 <param name="element" select="."/>
155 <choose>
156 <when test="$element/self::xsl:*">
157 <value-of select="true()"/>
158 </when>
159 <otherwise>
160 <variable name="namespace" select="namespace-uri($element)"/>
161 <variable name="extension-namespaces">
162 <for-each select="$element/ancestor-or-self::*/@xsl:extension-element-prefixes">
163 <variable name="prefixes"
164 select="concat(' ', normalize-space(.), ' ')"/>
165 <variable name="namespaces"
166 select="../namespace::*[contains($prefixes, concat(' ', name(), ' ')) or
167 (name() = '' and contains($prefixes, ' #default '))]"/>
168 <value-of select="$namespaces[. = $namespace]"/>
169 </for-each>
170 </variable>
171 <value-of select="$extension-namespaces != ''"/>
172 </otherwise>
173 </choose>
174 </template>
175
176 <template name="expand">
177 <param name="inside-xsl"/>
178 <variable name="params" select="$root/xsl:template[@name = name(current())]/xsl:param"/>
179
180 <XSL:call-template name="{name()}">
181 <if test="node() and $params">
182 <XSL:with-param name="{$params[1]/@name}">
183 <choose>
184 <when test="$inside-xsl">
185 <apply-templates mode="copy-xsl" select="node()"/>
186 </when>
187 <otherwise>
188 <variable name="pattern">
189 <call-template name="coord-pattern"/>
190 </variable>
191 <XSL:apply-templates select="{$pattern}/node()"/>
192 </otherwise>
193 </choose>
194 </XSL:with-param>
195 </if>
196
197 <for-each select="@*">
198 <variable name="expr">
199 <call-template name="before">
200 <with-param name="string" select="substring-after(., '{')"/>
201 <with-param name="target">}</with-param>
202 </call-template>
203 </variable>
204 <choose>
205 <when test="string-length($expr) = string-length(.) - 2">
206 <XSL:with-param name="{name()}" select="{$expr}"/>
207 </when>
208 <otherwise>
209 <XSL:with-param name="{name()}">
210 <call-template name="avt">
211 <with-param name="string" select="."/>
212 </call-template>
213 </XSL:with-param>
214 </otherwise>
215 </choose>
216 </for-each>
217 </XSL:call-template>
218 </template>
219
220 <template name="create-context">
221 <param name="elements" select="ancestor-or-self::*
222 [last() - 1 > position()]
223 /preceding-sibling::xsl:variable | ."/>
224
225 <variable name="pattern">
226 <call-template name="coord-pattern">
227 <with-param name="element" select="$elements[1]"/>
228 </call-template>
229 </variable>
230
231 <variable name="parent-pattern">
232 <call-template name="coord-pattern">
233 <with-param name="element" select="$elements[1]/.."/>
234 </call-template>
235 </variable>
236
237 <XSL:for-each select="{$parent-pattern}/*">
238 <XSL:if test="count({$pattern} | .) = 1">
239 <variable name="is-xsl">
240 <call-template name="is-xsl">
241 <with-param name="element" select="$elements[1]"/>
242 </call-template>
243 </variable>
244 <choose>
245 <when test="$is-xsl = 'true'">
246 <apply-templates mode="copy-xsl" select="$elements[1]"/>
247 <if test="$elements[2]">
248 <call-template name="create-context">
249 <with-param name="elements" select="$elements[position() > 1]"/>
250 </call-template>
251 </if>
252 </when>
253 <otherwise>
254 <copy>
255 <apply-templates select="@*"/>
256 <if test="node()">
257 <XSL:apply-templates select="node()"/>
258 </if>
259 </copy>
260 </otherwise>
261 </choose>
262 </XSL:if>
263 </XSL:for-each>
264 </template>
265
266 <template name="before">
267 <param name="string"/>
268 <param name="target"/>
269
270 <variable name="apos">'</variable>
271 <variable name="quot">"</variable>
272
273 <variable name="posapos" select="string-length(substring-before(
274 concat($string, $apos), $apos))"/>
275 <variable name="posquot" select="string-length(substring-before(
276 concat($string, $quot), $quot))"/>
277 <variable name="postarg" select="string-length(substring-before(
278 concat($string, $target), $target))"/>
279
280 <choose>
281 <when test="$posapos = $postarg and $posquot = $postarg">
282 <value-of select="$string"/>
283 </when>
284 <when test="$posapos > $postarg and $posquot > $postarg">
285 <value-of select="substring($string, 1, $postarg)"/>
286 </when>
287 <otherwise>
288 <variable name="delim">
289 <choose>
290 <when test="$posquot > $posapos">'</when>
291 <otherwise>"</otherwise>
292 </choose>
293 </variable>
294
295 <value-of select="substring-before($string, $delim)"/>
296 <value-of select="$delim"/>
297
298 <variable name="mid" select="substring-after($string, $delim)"/>
299
300 <choose>
301 <when test="contains($mid, $delim)">
302 <value-of select="substring-before($mid, $delim)"/>
303 <value-of select="$delim"/>
304
305 <call-template name="before">
306 <with-param name="string"
307 select="substring-after($mid, $delim)"/>
308 <with-param name="target"
309 select="$target"/>
310 </call-template>
311 </when>
312 <otherwise>
313 <value-of select="$mid"/>
314 </otherwise>
315 </choose>
316 </otherwise>
317 </choose>
318 </template>
319
320 <template name="avt">
321 <param name="string"/>
322
323 <variable name="before1" select="substring-before(concat($string, '{'), '{')"/>
324 <variable name="len1" select="string-length($before1)"/>
325
326 <variable name="before2" select="substring-before(concat($string, '}}'), '}}')"/>
327 <variable name="len2" select="string-length($before2)"/>
328
329 <choose>
330 <when test="$before1 = $string and $before2 = $string">
331 <value-of select="$string"/>
332 </when>
333 <when test="$len2 &lt; $len1">
334 <value-of select="$before2"/>
335 <text>}</text>
336 <call-template name="avt">
337 <with-param name="string" select="substring($string, $len2 + 3)"/>
338 </call-template>
339 </when>
340 <when test="substring($string, $len1 + 2, 1) = '{'">
341 <value-of select="$before1"/>
342 <text>{</text>
343 <call-template name="avt">
344 <with-param name="string" select="substring($string, $len1 + 3)"/>
345 </call-template>
346 </when>
347 <otherwise>
348 <variable name="mid" select="substring($string, $len1 + 2)"/>
349 <variable name="expr">
350 <call-template name="before">
351 <with-param name="string" select="$mid"/>
352 <with-param name="target">}</with-param>
353 </call-template>
354 </variable>
355 <value-of select="$before1"/>
356 <XSL:copy-of select="{$expr}"/>
357 <call-template name="avt">
358 <with-param name="string" select="substring($mid, string-length($expr) + 2)"/>
359 </call-template>
360 </otherwise>
361 </choose>
362 </template>
363
364 </transform>