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=
"/*/xsl:import |
25 /*/xsl:attribute-set |
26 /*/xsl:character-map |
27 /*/xsl:decimal-format |
29 /*/xsl:import-schema |
31 /*/xsl:namespace-alias |
34 /*/xsl:preserve-space |
40 select=
"$top-level-base |
45 select=
"$top-level-base |
47 [not(following-sibling::xsl:template/@name = @name)]"/>
51 <copy-of select=
"/*/namespace::*"/>
53 <for-each select=
"/*/@xsl:*">
54 <attribute name=
"{local-name()}">
55 <value-of select=
"."/>
59 <apply-templates mode=
"copy-xsl" select=
"$top-level-copy"/>
60 <apply-templates select=
"*"/>
65 <variable name=
"pattern">
66 <call-template name=
"coord-pattern"/>
69 <XSL:template match=
"*[generate-id() = generate-id(document('', /){$pattern})]">
70 <copy-of select=
"namespace::*"/>
72 <when test=
"/*/xsl:template[@name = name(current())]">
73 <call-template name=
"expand"/>
75 <when test=
"count($top-level | .) != count($top-level)">
76 <call-template name=
"create-context"/>
81 <if test=
"not(self::xsl:*)">
82 <apply-templates select=
"node()"/>
86 <template match=
"text()"/>
92 <template mode=
"copy-xsl" match=
"*[/*/xsl:template/@name = name()]">
94 <when test=
"ancestor::xsl:template[@name = name(current())]">
96 <XSL:when test=
"name() = '{name()}'">
98 <call-template name=
"copy-xsl-children"/>
103 <call-template name=
"copy-xsl-children"/>
109 <call-template name=
"expand"/>
114 <template mode=
"copy-xsl" match=
"@*|node()">
116 <call-template name=
"copy-xsl-children"/>
120 <template name=
"copy-xsl-children">
121 <copy-of select=
"namespace::*"/>
122 <apply-templates mode=
"copy-xsl" select=
"@*|node()"/>
125 <template name=
"coord-pattern">
126 <param name=
"element" select=
"."/>
128 <for-each select=
"$element/ancestor-or-self::*">
130 <value-of select=
"count(preceding-sibling::*) + 1"/>
135 <template name=
"expand">
136 <variable name=
"params" select=
"/*/xsl:template[@name = name(current())]/xsl:param"/>
138 <XSL:call-template name=
"{name()}">
140 <XSL:with-param name=
"{$params[1]/@name}">
142 <when test=
"ancestor-or-self::xsl:*">
143 <apply-templates mode=
"copy-xsl" select=
"node()"/>
146 <variable name=
"pattern">
147 <call-template name=
"coord-pattern"/>
149 <XSL:apply-templates select=
"{$pattern}/node()"/>
155 <for-each select=
"@*">
156 <XSL:with-param name=
"{name()}">
157 <call-template name=
"avt">
158 <with-param name=
"string" select=
"."/>
165 <template name=
"create-context">
166 <param name=
"elements" select=
"ancestor-or-self::*
167 [last() - 1 > position()]
168 /preceding-sibling::xsl:variable | ."/>
170 <variable name=
"pattern">
171 <call-template name=
"coord-pattern">
172 <with-param name=
"element" select=
"$elements[1]"/>
176 <variable name=
"parent-pattern">
177 <call-template name=
"coord-pattern">
178 <with-param name=
"element" select=
"$elements[1]/.."/>
182 <XSL:for-each select=
"{$parent-pattern}/*">
183 <XSL:if test=
"count({$pattern} | .) = 1">
185 <when test=
"$elements[1]/self::xsl:*">
186 <apply-templates mode=
"copy-xsl" select=
"$elements[1]"/>
187 <if test=
"$elements[2]">
188 <call-template name=
"create-context">
189 <with-param name=
"elements" select=
"$elements[position() > 1]"/>
195 <apply-templates select=
"@*"/>
197 <XSL:apply-templates select=
"node()"/>
206 <template name=
"before">
207 <param name=
"string"/>
208 <param name=
"target"/>
210 <variable name=
"apos">'
</variable>
211 <variable name=
"quot">"</variable>
213 <variable name="posapos
" select="string-length(substring-before(
214 concat($string, $apos), $apos))
"/>
215 <variable name="posquot
" select="string-length(substring-before(
216 concat($string, $quot), $quot))
"/>
217 <variable name="postarg
" select="string-length(substring-before(
218 concat($string, $target), $target))
"/>
221 <when test="$posapos = $postarg and $posquot = $postarg
">
222 <value-of select="$string
"/>
224 <when test="$posapos
> $postarg and $posquot
> $postarg"
>
225 <value-of select=
"substring($string, 1, $postarg)"/>
228 <variable name=
"delim">
230 <when test=
"$posquot > $posapos">'
</when>
231 <otherwise>"</otherwise>
235 <value-of select="substring-before($string, $delim)
"/>
236 <value-of select="$delim
"/>
238 <variable name="mid
" select="substring-after($string, $delim)
"/>
241 <when test="contains($mid, $delim)
">
242 <value-of select="substring-before($mid, $delim)
"/>
243 <value-of select="$delim
"/>
245 <call-template name="before
">
246 <with-param name="string
"
247 select="substring-after($mid, $delim)
"/>
248 <with-param name="target
"
253 <value-of select="$mid
"/>
260 <template name="avt
">
261 <param name="string
"/>
263 <variable name="before1
" select="substring-before(concat($string, '{'), '{')
"/>
264 <variable name="len1
" select="string-length($before1)
"/>
266 <variable name="before2
" select="substring-before(concat($string, '}}'), '}}')
"/>
267 <variable name="len2
" select="string-length($before2)
"/>
270 <when test="$before1 = $string and $before2 = $string
">
271 <value-of select="$string
"/>
273 <when test="$len2
< $len1
">
274 <value-of select="$before2
"/>
276 <call-template name="avt
">
277 <with-param name="string
" select="substring($string, $len2 +
3)
"/>
280 <when test="substring($string, $len1 +
2,
1) = '{'
">
281 <value-of select="$before1
"/>
283 <call-template name="avt
">
284 <with-param name="string
" select="substring($string, $len1 +
3)
"/>
288 <variable name="mid
" select="substring($string, $len1 +
2)
"/>
289 <variable name="expr
">
290 <call-template name="before
">
291 <with-param name="string
" select="$mid
"/>
292 <with-param name="target
">}</with-param>
295 <value-of select="$before1
"/>
296 <XSL:copy-of select="{$expr}
"/>
297 <call-template name="avt
">
298 <with-param name="string
" select="substring($mid, string-length($expr) +
2)
"/>