1 <?xml version=
"1.0" encoding=
"utf-8"?>
8 Copyright: (c) 2007 Mike Wetherell
9 Licence: wxWidgets licence
12 <transform xmlns=
"http://www.w3.org/1999/XSL/Transform"
13 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
17 <namespace-alias stylesheet-prefix=
"XSL" result-prefix=
"xsl"/>
19 <output indent=
"yes"/>
23 select=
"//*[not(ancestor-or-self::*[name() != name(/*)])]"/>
27 select=
"$root[position() > 1]"/>
30 xmlns:
func=
"http://exslt.org/functions"
32 select=
"$root/xsl:import |
34 $root/xsl:attribute-set |
35 $root/xsl:character-map |
36 $root/xsl:decimal-format |
38 $root/xsl:import-schema |
40 $root/xsl:namespace-alias |
43 $root/xsl:preserve-space |
44 $root/xsl:strip-space |
47 $root/func:function"/>
51 <copy-of select=
"$root/namespace::*"/>
53 <for-each select=
"$root/@xsl:*">
54 <attribute name=
"{local-name()}">
55 <value-of select=
"."/>
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=
"."/>
65 <apply-templates select=
"*"/>
70 <variable name=
"pattern">
71 <call-template name=
"coord-pattern"/>
74 <variable name=
"is-xsl">
75 <call-template name=
"is-xsl"/>
78 <XSL:template match=
"*[generate-id() = generate-id(document('', /){$pattern})]">
79 <copy-of select=
"namespace::*"/>
81 <when test=
"$root/xsl:template[@name = name(current())]">
82 <call-template name=
"expand">
83 <with-param name=
"inside-xsl" select=
"$is-xsl = 'true'"/>
86 <when test=
"count($includes | .) = count($includes)">
88 <XSL:apply-templates select=
"node()"/>
91 <when test=
"count($top-level | .) != count($top-level)">
92 <call-template name=
"create-context"/>
97 <if test=
"$is-xsl != 'true'">
98 <apply-templates select=
"node()"/>
102 <template match=
"text()"/>
104 <template match=
"@*">
108 <template mode=
"copy-xsl" match=
"*[//xsl:template[not(ancestor::*[name() != name(/*)])]/@name = name()]">
110 <when test=
"ancestor::xsl:template[@name = name(current())]">
112 <XSL:when test=
"name() = '{name()}'">
114 <call-template name=
"copy-xsl-children"/>
119 <call-template name=
"copy-xsl-children"/>
125 <call-template name=
"expand">
126 <with-param name=
"inside-xsl" select=
"true()"/>
132 <template mode=
"copy-xsl" match=
"@*|node()">
134 <call-template name=
"copy-xsl-children"/>
138 <template name=
"copy-xsl-children">
139 <copy-of select=
"namespace::*"/>
140 <apply-templates mode=
"copy-xsl" select=
"@*|node()"/>
143 <template name=
"coord-pattern">
144 <param name=
"element" select=
"."/>
146 <for-each select=
"$element/ancestor-or-self::*">
148 <value-of select=
"count(preceding-sibling::*) + 1"/>
153 <template name=
"is-xsl">
154 <param name=
"element" select=
"."/>
156 <when test=
"$element/self::xsl:*">
157 <value-of select=
"true()"/>
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]"/>
171 <value-of select=
"$extension-namespaces != ''"/>
176 <template name=
"expand">
177 <param name=
"inside-xsl"/>
178 <variable name=
"params" select=
"$root/xsl:template[@name = name(current())]/xsl:param"/>
180 <XSL:call-template name=
"{name()}">
181 <if test=
"node() and $params">
182 <XSL:with-param name=
"{$params[1]/@name}">
184 <when test=
"$inside-xsl">
185 <apply-templates mode=
"copy-xsl" select=
"node()"/>
188 <variable name=
"pattern">
189 <call-template name=
"coord-pattern"/>
191 <XSL:apply-templates select=
"{$pattern}/node()"/>
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>
205 <when test=
"string-length($expr) = string-length(.) - 2">
206 <XSL:with-param name=
"{name()}" select=
"{$expr}"/>
209 <XSL:with-param name=
"{name()}">
210 <call-template name=
"avt">
211 <with-param name=
"string" select=
"."/>
220 <template name=
"create-context">
221 <param name=
"elements" select=
"ancestor-or-self::*
222 [last() - 1 > position()]
223 /preceding-sibling::xsl:variable | ."/>
225 <variable name=
"pattern">
226 <call-template name=
"coord-pattern">
227 <with-param name=
"element" select=
"$elements[1]"/>
231 <variable name=
"parent-pattern">
232 <call-template name=
"coord-pattern">
233 <with-param name=
"element" select=
"$elements[1]/.."/>
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]"/>
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]"/>
255 <apply-templates select=
"@*"/>
257 <XSL:apply-templates select=
"node()"/>
266 <template name=
"before">
267 <param name=
"string"/>
268 <param name=
"target"/>
270 <variable name=
"apos">'
</variable>
271 <variable name=
"quot">"</variable>
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))
"/>
281 <when test="$posapos = $postarg and $posquot = $postarg
">
282 <value-of select="$string
"/>
284 <when test="$posapos
> $postarg and $posquot
> $postarg"
>
285 <value-of select=
"substring($string, 1, $postarg)"/>
288 <variable name=
"delim">
290 <when test=
"$posquot > $posapos">'
</when>
291 <otherwise>"</otherwise>
295 <value-of select="substring-before($string, $delim)
"/>
296 <value-of select="$delim
"/>
298 <variable name="mid
" select="substring-after($string, $delim)
"/>
301 <when test="contains($mid, $delim)
">
302 <value-of select="substring-before($mid, $delim)
"/>
303 <value-of select="$delim
"/>
305 <call-template name="before
">
306 <with-param name="string
"
307 select="substring-after($mid, $delim)
"/>
308 <with-param name="target
"
313 <value-of select="$mid
"/>
320 <template name="avt
">
321 <param name="string
"/>
323 <variable name="before1
" select="substring-before(concat($string, '{'), '{')
"/>
324 <variable name="len1
" select="string-length($before1)
"/>
326 <variable name="before2
" select="substring-before(concat($string, '}}'), '}}')
"/>
327 <variable name="len2
" select="string-length($before2)
"/>
330 <when test="$before1 = $string and $before2 = $string
">
331 <value-of select="$string
"/>
333 <when test="$len2
< $len1
">
334 <value-of select="$before2
"/>
336 <call-template name="avt
">
337 <with-param name="string
" select="substring($string, $len2 +
3)
"/>
340 <when test="substring($string, $len1 +
2,
1) = '{'
">
341 <value-of select="$before1
"/>
343 <call-template name="avt
">
344 <with-param name="string
" select="substring($string, $len1 +
3)
"/>
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>
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)
"/>