Code

Fix for rectangle RadiusY and RadiusX in XAML export.
[inkscape.git] / share / extensions / svg2xaml.xsl
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 \r
3 <!--\r
4 Copyright (c) 2005-2007 Toine de Greef (a.degreef@chello.nl)\r
5 \r
6 Permission is hereby granted, free of charge, to any person obtaining a copy\r
7 of this software and associated documentation files (the "Software"), to deal\r
8 in the Software without restriction, including without limitation the rights\r
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
10 copies of the Software, and to permit persons to whom the Software is\r
11 furnished to do so, subject to the following conditions:\r
12 \r
13 The above copyright notice and this permission notice shall be included in\r
14 all copies or substantial portions of the Software.\r
15 \r
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
22 THE SOFTWARE.\r
23 -->\r
24 \r
25 <xsl:stylesheet version="1.0"\r
26 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
27 xmlns:xlink="http://www.w3.org/1999/xlink"\r
28 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\r
29 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
30 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
31 xmlns:msxsl="urn:schemas-microsoft-com:xslt"\r
32 exclude-result-prefixes="rdf xlink msxsl">\r
33 \r
34 <xsl:strip-space elements="*" />\r
35 <xsl:output method="xml" encoding="UTF-8"/>\r
36 \r
37 <xsl:param name="silverlight_compatible" select="1" />\r
38 \r
39 <xsl:template name="template_color">\r
40   <xsl:param name="colorspec" />\r
41   <xsl:param name="opacityspec" />\r
42   <xsl:choose>\r
43     <xsl:when test="starts-with($colorspec, 'rgb(') and not(contains($colorspec , '%'))">\r
44       <xsl:value-of select="'#'" />\r
45       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number($opacityspec) * 255" /></xsl:with-param></xsl:call-template></xsl:if>\r
46       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="substring-before(substring-after($colorspec, 'rgb('), ',')" /></xsl:with-param></xsl:call-template>\r
47       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), ',')" /></xsl:with-param></xsl:call-template>\r
48       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), ')')" /></xsl:with-param></xsl:call-template>\r
49     </xsl:when>\r
50     <xsl:when test="starts-with($colorspec, 'rgb(') and contains($colorspec , '%')">\r
51       <xsl:value-of select="'#'" />\r
52       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number($opacityspec) * 255" /></xsl:with-param></xsl:call-template></xsl:if>\r
53       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number(substring-before(substring-after($colorspec, 'rgb('), '%,')) * 255 div 100" /></xsl:with-param></xsl:call-template>\r
54       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number(substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), '%,')) * 255 div 100" /></xsl:with-param></xsl:call-template>\r
55       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number(substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), '%)')) * 255 div 100" /></xsl:with-param></xsl:call-template>\r
56     </xsl:when>\r
57     <xsl:when test="starts-with($colorspec, '#')">\r
58       <xsl:value-of select="'#'" />\r
59       <xsl:if test="$opacityspec != ''"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number($opacityspec) * 255" /></xsl:with-param></xsl:call-template></xsl:if>\r
60       <xsl:choose>\r
61         <xsl:when test="string-length(substring-after($colorspec, '#')) = 3">\r
62           <xsl:variable name="colorspec3"><xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" /></xsl:variable>\r
63           <xsl:value-of select="concat(substring($colorspec3, 1, 1), substring($colorspec3, 1, 1))" />\r
64           <xsl:value-of select="concat(substring($colorspec3, 2, 1), substring($colorspec3, 2, 1))" />\r
65           <xsl:value-of select="concat(substring($colorspec3, 3, 1), substring($colorspec3, 3, 1))" />\r
66         </xsl:when>\r
67         <xsl:otherwise><xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" /></xsl:otherwise>\r
68       </xsl:choose>  \r
69     </xsl:when>\r
70     <xsl:otherwise>\r
71       <xsl:variable name="named_color_hex" select="document('colors.xml')/colors/color[@name = translate($colorspec, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]/@hex" />\r
72       <xsl:choose>\r
73         <xsl:when test="$named_color_hex and $named_color_hex != ''">\r
74           <xsl:value-of select="'#'" />\r
75           <xsl:if test="$opacityspec != '' and number($opacityspec) != 1"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number($opacityspec) * 255" /></xsl:with-param></xsl:call-template></xsl:if>\r
76           <xsl:value-of select="substring-after($named_color_hex, '#')" />\r
77         </xsl:when>\r
78         <xsl:otherwise><xsl:value-of select="$colorspec" /></xsl:otherwise>\r
79       </xsl:choose>  \r
80     </xsl:otherwise>\r
81   </xsl:choose>\r
82 </xsl:template>\r
83 \r
84 <xsl:template mode="fill" match="*">\r
85   <xsl:choose>\r
86     <xsl:when test="@fill and starts-with(@fill, 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@fill, 'url(#'), ')'), '}')" /></xsl:when>\r
87     <xsl:when test="@fill"><xsl:value-of select="@fill" /></xsl:when>\r
88     <xsl:when test="@style and contains(@style, 'fill:') and starts-with(substring-after(@style, 'fill:'), 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" /></xsl:when>\r
89     <xsl:when test="@style and contains(@style, 'fill:')">\r
90       <xsl:variable name="Fill" select="substring-after(@style, 'fill:')" />\r
91       <xsl:choose>\r
92         <xsl:when test="contains($Fill, ';')">\r
93           <xsl:value-of select="substring-before($Fill, ';')" />\r
94         </xsl:when>  \r
95         <xsl:otherwise><xsl:value-of select="$Fill" /></xsl:otherwise>\r
96       </xsl:choose> \r
97     </xsl:when>\r
98     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="fill" select="parent::*"/></xsl:when>\r
99   </xsl:choose>\r
100 </xsl:template>\r
101 \r
102 <xsl:template mode="fill_opacity" match="*">\r
103   <xsl:choose>\r
104     <xsl:when test="@fill-opacity"><xsl:value-of select="@fill-opacity" /></xsl:when>\r
105     <xsl:when test="@style and contains(@style, 'fill-opacity:')">\r
106       <xsl:variable name="Opacity" select="substring-after(@style, 'fill-opacity:')" />\r
107       <xsl:choose>\r
108         <xsl:when test="contains($Opacity, ';')"><xsl:value-of select="substring-before($Opacity, ';')" /></xsl:when>\r
109         <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
110       </xsl:choose>  \r
111     </xsl:when>\r
112     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="fill_opacity" select="parent::*" /></xsl:when>\r
113   </xsl:choose>  \r
114 </xsl:template>\r
115 \r
116 \r
117 <xsl:template mode="fill_rule" match="*">\r
118   <xsl:choose>\r
119     <xsl:when test="@fill-rule and (@fill-rule = 'nonzero' or @fill-rule = 'evenodd')"><xsl:attribute name="FillRule"><xsl:value-of select="@fill-rule" /></xsl:attribute></xsl:when>\r
120     <xsl:when test="@style and contains(@style, 'fill-rule:')">\r
121       <xsl:variable name="FillRule" select="substring-after(@style, 'fill-rule:')" />\r
122       <xsl:choose>\r
123         <xsl:when test="contains($FillRule, ';')">\r
124           <xsl:if test="substring-before($FillRule, ';') = 'nonzero' or substring-before($FillRule, ';') = 'evenodd'"><xsl:attribute name="FillRule"><xsl:value-of select="substring-before($FillRule, ';')" /></xsl:attribute></xsl:if>\r
125         </xsl:when>\r
126         <xsl:when test="$FillRule = 'nonzero' or $FillRule = 'evenodd'"><xsl:attribute name="FillRule"><xsl:value-of select="$FillRule" /></xsl:attribute></xsl:when>\r
127       </xsl:choose>  \r
128     </xsl:when>\r
129     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="fill_rule" select="parent::*"/></xsl:when>\r
130     <xsl:otherwise><xsl:attribute name="FillRule">NonZero</xsl:attribute></xsl:otherwise>\r
131   </xsl:choose>  \r
132 </xsl:template>\r
133 \r
134 <xsl:template mode="template_fill" match="*">\r
135   <xsl:variable name="fill"><xsl:apply-templates mode="fill" select="." /></xsl:variable>\r
136   <xsl:variable name="fill_opacity"><xsl:apply-templates mode="fill_opacity" select="." /></xsl:variable>\r
137   <xsl:if test="not($fill = 'none')">\r
138     <xsl:attribute name="Fill">\r
139       <xsl:choose>\r
140         <xsl:when test="$fill != ''">\r
141           <xsl:call-template name="template_color">\r
142             <xsl:with-param name="colorspec">\r
143               <xsl:if test="$fill != 'none'"><xsl:value-of select="$fill" /></xsl:if>\r
144             </xsl:with-param>\r
145             <xsl:with-param name="opacityspec"><xsl:value-of select="$fill_opacity" /></xsl:with-param>\r
146           </xsl:call-template>\r
147         </xsl:when>\r
148         <xsl:otherwise>#000000</xsl:otherwise>\r
149       </xsl:choose>\r
150     </xsl:attribute>\r
151   </xsl:if>   \r
152 </xsl:template>\r
153 \r
154 <xsl:template mode="stroke" match="*">\r
155   <xsl:choose>\r
156     <xsl:when test="@stroke and starts-with(@stroke, 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@stroke, 'url(#'), ')'), '}')" /></xsl:when>\r
157     <xsl:when test="@stroke and @stroke != 'none'"><xsl:value-of select="@stroke" /></xsl:when>\r
158     <xsl:when test="@style and contains(@style, 'stroke:') and starts-with(substring-after(@style, 'stroke:'), 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" /></xsl:when>    \r
159     <xsl:when test="@style and contains(@style, 'stroke:')">\r
160       <xsl:variable name="Stroke" select="substring-after(@style, 'stroke:')" />\r
161       <xsl:choose>\r
162         <xsl:when test="contains($Stroke, ';')">\r
163           <xsl:if test="substring-before($Stroke, ';') != 'none'"><xsl:value-of select="substring-before($Stroke, ';')" /></xsl:if>\r
164         </xsl:when>  \r
165         <xsl:when test="$Stroke != 'none'"><xsl:value-of select="$Stroke" /></xsl:when>\r
166       </xsl:choose>  \r
167     </xsl:when>\r
168     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke" select="parent::*"/></xsl:when>\r
169   </xsl:choose>\r
170 </xsl:template>\r
171 \r
172 \r
173 <xsl:template mode="stroke_opacity" match="*">\r
174   <xsl:choose>\r
175     <xsl:when test="@stroke-opacity"><xsl:value-of select="@stroke-opacity" /></xsl:when>\r
176     <xsl:when test="@style and contains(@style, 'stroke-opacity:')">\r
177       <xsl:variable name="Opacity" select="substring-after(@style, 'stroke-opacity:')" />\r
178       <xsl:choose>\r
179         <xsl:when test="contains($Opacity, ';')"><xsl:value-of select="substring-before($Opacity, ';')" /></xsl:when>\r
180         <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
181       </xsl:choose>  \r
182     </xsl:when>\r
183     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_opacity" select="parent::*" /></xsl:when>\r
184   </xsl:choose>  \r
185 </xsl:template>\r
186 \r
187 <xsl:template mode="template_stroke" match="*">\r
188   <xsl:variable name="stroke"><xsl:apply-templates mode="stroke" select="." /></xsl:variable>\r
189   <xsl:variable name="stroke_opacity"><xsl:apply-templates mode="stroke_opacity" select="." /></xsl:variable>\r
190   <xsl:if test="$stroke != ''">\r
191     <xsl:attribute name="Stroke">\r
192       <xsl:call-template name="template_color">\r
193         <xsl:with-param name="colorspec"><xsl:value-of select="$stroke" /></xsl:with-param>\r
194         <xsl:with-param name="opacityspec"><xsl:value-of select="$stroke_opacity" /></xsl:with-param>\r
195       </xsl:call-template>  \r
196     </xsl:attribute>\r
197   </xsl:if>\r
198 </xsl:template>\r
199 \r
200 <xsl:template mode="stroke_width" match="*">\r
201   <xsl:choose>\r
202     <xsl:when test="@stroke-width"><xsl:attribute name="StrokeThickness"><xsl:value-of select="@stroke-width" /></xsl:attribute></xsl:when>\r
203     <xsl:when test="@style and contains(@style, 'stroke-width:')">\r
204       <xsl:variable name="StrokeThickness" select="substring-after(@style, 'stroke-width:')" />\r
205       <xsl:attribute name="StrokeThickness">\r
206         <xsl:choose>\r
207           <xsl:when test="contains($StrokeThickness, ';')"><xsl:value-of select="substring-before($StrokeThickness, ';')" /></xsl:when>\r
208           <xsl:otherwise><xsl:value-of select="$StrokeThickness" /></xsl:otherwise>\r
209         </xsl:choose>  \r
210       </xsl:attribute>\r
211     </xsl:when>\r
212     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_width" select="parent::*"/></xsl:when>\r
213   </xsl:choose>  \r
214 </xsl:template>\r
215 \r
216 <xsl:template mode="stroke_miterlimit" match="*">\r
217   <xsl:choose>\r
218     <xsl:when test="@stroke-miterlimit"><xsl:attribute name="StrokeMiterLimit"><xsl:value-of select="@stroke-miterlimit" /></xsl:attribute></xsl:when>\r
219     <xsl:when test="@style and contains(@style, 'stroke-miterlimit:')">\r
220       <xsl:variable name="StrokeMiterLimit" select="substring-after(@style, 'stroke-miterlimit:')" />\r
221       <xsl:attribute name="StrokeMiterLimit">\r
222         <xsl:choose>\r
223           <xsl:when test="contains($StrokeMiterLimit, ';')"><xsl:value-of select="substring-before($StrokeMiterLimit, ';')" /></xsl:when>\r
224           <xsl:otherwise><xsl:value-of select="$StrokeMiterLimit" /></xsl:otherwise>\r
225         </xsl:choose>  \r
226       </xsl:attribute>\r
227     </xsl:when>\r
228     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_miterlimit" select="parent::*"/></xsl:when>\r
229   </xsl:choose>  \r
230 </xsl:template>\r
231 \r
232 <xsl:template mode="stroke_dasharray" match="*">\r
233   <!-- stroke-dasharray="10,30,20,30" becomes StrokeDashArray="1 3 2 3" ?? -->\r
234   <xsl:choose>\r
235     <xsl:when test="@stroke-dasharray and @stroke-dasharray != 'none'"><xsl:attribute name="StrokeDashArray"><xsl:value-of select="@stroke-dasharray" /></xsl:attribute></xsl:when>\r
236     <xsl:when test="@style and contains(@style, 'stroke-dasharray:')">\r
237       <xsl:variable name="StrokeDashArray" select="substring-after(@style, 'stroke-dasharray:')" />\r
238       <xsl:choose>\r
239         <xsl:when test="contains($StrokeDashArray, ';')">\r
240           <xsl:if test="substring-before($StrokeDashArray, ';') != 'none'"><xsl:attribute name="StrokeDashArray"><xsl:value-of select="substring-before($StrokeDashArray, ';')" /></xsl:attribute></xsl:if>\r
241         </xsl:when>\r
242         <xsl:when test="$StrokeDashArray != 'none'"><xsl:attribute name="StrokeDashArray"><xsl:value-of select="$StrokeDashArray" /></xsl:attribute></xsl:when>\r
243       </xsl:choose>  \r
244     </xsl:when>\r
245     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_dasharray" select="parent::*"/></xsl:when>\r
246   </xsl:choose>  \r
247 </xsl:template>\r
248 \r
249 <xsl:template mode="stroke_dashoffset" match="*">\r
250   <xsl:choose>\r
251     <xsl:when test="@stroke-dashoffset"><xsl:attribute name="StrokeDashOffset"><xsl:value-of select="@stroke-dashoffset" /></xsl:attribute></xsl:when>\r
252     <xsl:when test="@style and contains(@style, 'stroke-dashoffset:')">\r
253       <xsl:variable name="StrokeDashOffset" select="substring-after(@style, 'stroke-dashoffset:')" />\r
254       <xsl:attribute name="StrokeDashOffset">\r
255         <xsl:choose>\r
256           <xsl:when test="contains($StrokeDashOffset, ';')"><xsl:value-of select="substring-before($StrokeDashOffset, ';')" /></xsl:when>\r
257           <xsl:otherwise><xsl:value-of select="$StrokeDashOffset" /></xsl:otherwise>\r
258         </xsl:choose>  \r
259       </xsl:attribute>\r
260     </xsl:when>\r
261     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_dashoffset" select="parent::*"/></xsl:when>\r
262   </xsl:choose>  \r
263 </xsl:template>\r
264 \r
265 <xsl:template name="linejoin_svg_to_xaml">\r
266   <xsl:param name="linejoin" />\r
267   <xsl:choose>\r
268     <xsl:when test="$linejoin = 'bevel'">Bevel</xsl:when>\r
269     <xsl:when test="$linejoin = 'round'">Round</xsl:when>\r
270     <xsl:otherwise>Miter</xsl:otherwise>\r
271   </xsl:choose>\r
272 </xsl:template>\r
273 \r
274 <xsl:template mode="stroke_linejoin" match="*">\r
275   <xsl:choose>\r
276     <xsl:when test="@stroke-miterlimit">\r
277       <xsl:attribute name="StrokeLineJoin">\r
278         <xsl:call-template name="linejoin_svg_to_xaml"><xsl:with-param name="linejoin"><xsl:value-of select="@stroke-linejoin" /></xsl:with-param></xsl:call-template>\r
279       </xsl:attribute></xsl:when>\r
280     <xsl:when test="@style and contains(@style, 'stroke-linejoin:')">\r
281       <xsl:variable name="StrokeLineJoin" select="substring-after(@style, 'stroke-linejoin:')" />\r
282       <xsl:attribute name="StrokeLineJoin">\r
283         <xsl:choose>\r
284           <xsl:when test="contains($StrokeLineJoin, ';')">\r
285             <xsl:call-template name="linejoin_svg_to_xaml"><xsl:with-param name="linejoin"><xsl:value-of select="substring-before($StrokeLineJoin, ';')" /></xsl:with-param></xsl:call-template>\r
286           </xsl:when>\r
287           <xsl:otherwise>\r
288             <xsl:call-template name="linejoin_svg_to_xaml"><xsl:with-param name="linejoin"><xsl:value-of select="$StrokeLineJoin" /></xsl:with-param></xsl:call-template>\r
289           </xsl:otherwise>\r
290         </xsl:choose>  \r
291       </xsl:attribute>\r
292     </xsl:when>\r
293     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_linejoin" select="parent::*"/></xsl:when>\r
294   </xsl:choose>  \r
295 </xsl:template>\r
296 \r
297 <xsl:template name="linecap_svg_to_xaml">\r
298   <xsl:param name="linecap" />\r
299   <xsl:choose>\r
300     <xsl:when test="$linecap = 'round'">Round</xsl:when>\r
301     <xsl:when test="$linecap = 'square'">Square</xsl:when>\r
302     <xsl:otherwise>Flat</xsl:otherwise>\r
303   </xsl:choose>\r
304 </xsl:template>\r
305 \r
306 <xsl:template mode="stroke_linecap" match="*">\r
307   <xsl:choose>\r
308     <xsl:when test="@stroke-linecap">\r
309       <xsl:attribute name="StrokeStartLineCap">\r
310         <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="@stroke-linecap" /></xsl:with-param></xsl:call-template>\r
311       </xsl:attribute>\r
312       <xsl:attribute name="StrokeEndLineCap">\r
313         <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="@stroke-linecap" /></xsl:with-param></xsl:call-template>\r
314       </xsl:attribute></xsl:when>\r
315     <xsl:when test="@style and contains(@style, 'stroke-linecap:')">\r
316       <xsl:variable name="StrokeStartLineCap" select="substring-after(@style, 'stroke-linecap:')" />\r
317       <xsl:variable name="StrokeEndLineCap" select="substring-after(@style, 'stroke-linecap:')" />\r
318       <xsl:attribute name="StrokeStartLineCap">\r
319         <xsl:choose>\r
320           <xsl:when test="contains($StrokeStartLineCap, ';')">\r
321             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="substring-before($StrokeStartLineCap, ';')" /></xsl:with-param></xsl:call-template>\r
322           </xsl:when>\r
323           <xsl:otherwise>\r
324             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="$StrokeStartLineCap" /></xsl:with-param></xsl:call-template>\r
325           </xsl:otherwise>\r
326         </xsl:choose>  \r
327       </xsl:attribute>\r
328       <xsl:attribute name="StrokeEndLineCap">\r
329         <xsl:choose>\r
330           <xsl:when test="contains($StrokeEndLineCap, ';')">\r
331             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="substring-before($StrokeEndLineCap, ';')" /></xsl:with-param></xsl:call-template>\r
332           </xsl:when>\r
333           <xsl:otherwise>\r
334             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="$StrokeEndLineCap" /></xsl:with-param></xsl:call-template>\r
335           </xsl:otherwise>\r
336         </xsl:choose>  \r
337       </xsl:attribute>\r
338     </xsl:when>\r
339     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_linecap" select="parent::*"/></xsl:when>\r
340   </xsl:choose>  \r
341 </xsl:template>\r
342 \r
343 <xsl:template mode="resources" match="*">\r
344   <!-- should be in-depth -->\r
345   <xsl:if test="ancestor::*[name(.) = 'defs']"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
346 </xsl:template>  \r
347 \r
348 <xsl:template name="to_hex">\r
349   <xsl:param name="convert" />\r
350   <xsl:value-of select="concat(substring('0123456789ABCDEF', 1 + floor(round($convert) div 16), 1), substring('0123456789ABCDEF', 1 + round($convert) mod 16, 1))" />\r
351 </xsl:template>\r
352 \r
353 <xsl:template mode="stop_color" match="*">\r
354   <xsl:variable name="Opacity">\r
355     <xsl:choose>\r
356       <xsl:when test="@stop-opacity"><xsl:value-of select="@stop-opacity" /></xsl:when>\r
357       <xsl:when test="@style and contains(@style, 'stop-opacity:')">\r
358         <xsl:variable name="temp_opacity" select="substring-after(@style, 'stop-opacity:')" />\r
359         <xsl:choose>\r
360           <xsl:when test="contains($temp_opacity, ';')"><xsl:value-of select="substring-before($temp_opacity, ';')" /></xsl:when>\r
361           <xsl:otherwise><xsl:value-of select="$temp_opacity" /></xsl:otherwise>\r
362         </xsl:choose>          \r
363       </xsl:when>\r
364       <xsl:otherwise><xsl:value-of select="''" /></xsl:otherwise>\r
365     </xsl:choose>\r
366   </xsl:variable>\r
367   <xsl:variable name="hex_opacity">\r
368     <xsl:choose>\r
369       <xsl:when test="$Opacity != ''"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number($Opacity) * 255" /></xsl:with-param></xsl:call-template>  </xsl:when>  \r
370       <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
371     </xsl:choose>  \r
372   </xsl:variable>\r
373   <xsl:variable name="stopcolor">\r
374     <xsl:choose>\r
375       <xsl:when test="@stop-color">\r
376         <xsl:call-template name="template_color"><xsl:with-param name="colorspec"><xsl:value-of select="@stop-color" /></xsl:with-param></xsl:call-template>  \r
377       </xsl:when>\r
378       <xsl:when test="@style and contains(@style, 'stop-color:')">\r
379         <xsl:variable name="Color" select="substring-after(@style, 'stop-color:')" />\r
380         <xsl:choose>\r
381           <xsl:when test="contains($Color, ';')">\r
382             <xsl:call-template name="template_color"><xsl:with-param name="colorspec"><xsl:value-of select="substring-before($Color, ';')" /></xsl:with-param></xsl:call-template>  \r
383           </xsl:when>\r
384           <xsl:otherwise>\r
385             <xsl:call-template name="template_color"><xsl:with-param name="colorspec"><xsl:value-of select="$Color" /></xsl:with-param></xsl:call-template>  \r
386           </xsl:otherwise>\r
387         </xsl:choose>  \r
388       </xsl:when>\r
389       <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stop_color" select="parent::*"/></xsl:when>\r
390       <xsl:otherwise>#000</xsl:otherwise>\r
391     </xsl:choose>  \r
392   </xsl:variable>\r
393   <xsl:attribute name="Color">\r
394     <xsl:choose>\r
395       <xsl:when test="$hex_opacity != '' and starts-with($stopcolor, '#')"><xsl:value-of select="concat('#', $hex_opacity, substring-after($stopcolor, '#'))" /></xsl:when>\r
396       <xsl:otherwise><xsl:value-of select="$stopcolor" /></xsl:otherwise>\r
397     </xsl:choose>\r
398   </xsl:attribute>\r
399 </xsl:template>\r
400 \r
401 <xsl:template mode="stop_opacity" match="*">\r
402   <xsl:choose>\r
403     <xsl:when test="@stop-opacity"><xsl:attribute name="Opacity"><xsl:value-of select="@stop-opacity" /></xsl:attribute></xsl:when>\r
404     <xsl:when test="@style and contains(@style, 'stop-opacity:')">\r
405       <xsl:variable name="Opacity" select="substring-after(@style, 'stop-opacity:')" />\r
406       <xsl:attribute name="Opacity">\r
407         <xsl:choose>\r
408           <xsl:when test="contains($Opacity, ';')"><xsl:value-of select="substring-before($Opacity, ';')" /></xsl:when>\r
409           <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
410         </xsl:choose>  \r
411       </xsl:attribute>\r
412     </xsl:when>\r
413     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stop_opacity" select="parent::*"/></xsl:when>\r
414   </xsl:choose>  \r
415 </xsl:template>\r
416 \r
417 <xsl:template mode="offset" match="*">\r
418   <xsl:choose>\r
419     <xsl:when test="@offset">\r
420       <xsl:attribute name="Offset">\r
421         <xsl:choose>\r
422           <xsl:when test="contains(@offset, '%')"><xsl:value-of select="number(substring-before(@offset, '%')) div 100" /></xsl:when>\r
423           <xsl:otherwise><xsl:value-of select="@offset" /></xsl:otherwise>\r
424         </xsl:choose>  \r
425       </xsl:attribute>\r
426     </xsl:when>\r
427     <xsl:when test="@style and contains(@style, 'offset:')">\r
428       <xsl:variable name="Offset" select="substring-after(@style, 'offset:')" />\r
429       <xsl:attribute name="Offset">\r
430         <xsl:choose>\r
431           <xsl:when test="contains($Offset, '%')"><xsl:value-of select="number(substring-before($Offset, '%')) div 100" /></xsl:when>        \r
432           <xsl:when test="contains($Offset, ';')"><xsl:value-of select="substring-before($Offset, ';')" /></xsl:when>\r
433           <xsl:otherwise><xsl:value-of select="$Offset" /></xsl:otherwise>\r
434         </xsl:choose>  \r
435       </xsl:attribute>\r
436     </xsl:when>\r
437     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stop_offset" select="parent::*"/></xsl:when>\r
438   </xsl:choose>  \r
439 </xsl:template>\r
440 \r
441 <xsl:template name="parse_transform">\r
442   <xsl:param name="input" />\r
443   <xsl:choose>\r
444     <xsl:when test="starts-with($input, 'matrix(')">\r
445       <MatrixTransform><xsl:attribute name="Matrix"><xsl:value-of select="substring-before(substring-after($input, 'matrix('), ')')" /></xsl:attribute></MatrixTransform>\r
446       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>      \r
447     </xsl:when>\r
448     <xsl:when test="starts-with($input, 'scale(')">\r
449       <ScaleTransform>\r
450         <xsl:variable name="scale" select="substring-before(substring-after($input, 'scale('), ')')" />\r
451         <xsl:choose>\r
452           <xsl:when test="contains($scale, ',')">\r
453             <xsl:attribute name="ScaleX"><xsl:value-of select="substring-before($scale, ',')" /></xsl:attribute>\r
454             <xsl:attribute name="ScaleY"><xsl:value-of select="substring-after($scale, ',')" /></xsl:attribute>\r
455           </xsl:when>\r
456           <xsl:otherwise>\r
457             <xsl:attribute name="ScaleX"><xsl:value-of select="$scale" /></xsl:attribute>\r
458             <xsl:attribute name="ScaleY"><xsl:value-of select="$scale" /></xsl:attribute>\r
459           </xsl:otherwise>\r
460         </xsl:choose>  \r
461       </ScaleTransform>\r
462       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
463     </xsl:when>\r
464     <xsl:when test="starts-with($input, 'rotate(')">\r
465       <RotateTransform>\r
466         <xsl:attribute name="Angle"><xsl:value-of select="substring-before(substring-after($input, 'rotate('), ')')" /></xsl:attribute>\r
467         <xsl:if test="@rx"><xsl:attribute name="CenterX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>\r
468         <xsl:if test="@ry"><xsl:attribute name="CenterY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>\r
469       </RotateTransform>\r
470       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
471     </xsl:when>\r
472     <xsl:when test="starts-with($input, 'skewX(')">\r
473       <SkewTransform>\r
474         <xsl:attribute name="AngleX"><xsl:value-of select="substring-before(substring-after($input, 'skewX('), ')')" /></xsl:attribute>\r
475         <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
476       </SkewTransform>\r
477     </xsl:when>\r
478     <xsl:when test="starts-with($input, 'skewY(')">\r
479       <SkewTransform>\r
480         <xsl:attribute name="AngleY"><xsl:value-of select="substring-before(substring-after($input, 'skewY('), ')')" /></xsl:attribute>\r
481         <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
482       </SkewTransform>\r
483     </xsl:when>\r
484     <xsl:when test="starts-with($input, 'translate(')">\r
485       <TranslateTransform>\r
486         <xsl:variable name="translate" select="substring-before(substring-after($input, 'translate('), ')')" />\r
487         <xsl:choose>\r
488           <xsl:when test="contains($translate, ',')">\r
489             <xsl:attribute name="X"><xsl:value-of select="substring-before($translate, ',')" /></xsl:attribute>\r
490             <xsl:attribute name="Y"><xsl:value-of select="substring-after($translate, ',')" /></xsl:attribute>\r
491           </xsl:when>\r
492           <xsl:when test="contains($translate, ' ')">\r
493             <xsl:attribute name="X"><xsl:value-of select="substring-before($translate, ' ')" /></xsl:attribute>\r
494             <xsl:attribute name="Y"><xsl:value-of select="substring-after($translate, ' ')" /></xsl:attribute>\r
495           </xsl:when>\r
496           <xsl:otherwise><xsl:attribute name="X"><xsl:value-of select="$translate" /></xsl:attribute></xsl:otherwise>\r
497         </xsl:choose>  \r
498       </TranslateTransform>\r
499       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
500     </xsl:when>  \r
501   </xsl:choose>\r
502 </xsl:template>\r
503 \r
504 <xsl:template mode="transform" match="*[@transform or @gradientTransform]">\r
505   <xsl:param name="mapped_type" />\r
506   <xsl:variable name="transform">\r
507     <xsl:choose>\r
508        <xsl:when test="@transform"><xsl:value-of select="@transform" /></xsl:when>\r
509        <xsl:otherwise><xsl:value-of select="@gradientTransform" /></xsl:otherwise>\r
510     </xsl:choose>\r
511   </xsl:variable>\r
512   <xsl:variable name="transform_nodes">\r
513     <xsl:call-template name="parse_transform">\r
514       <xsl:with-param name="input" select="$transform" />\r
515     </xsl:call-template>\r
516   </xsl:variable>\r
517   \r
518   <xsl:comment>\r
519     <xsl:value-of select="name(.)" />\r
520   </xsl:comment>\r
521 \r
522   <xsl:choose>\r
523     <xsl:when test="system-property('xsl:vendor') = 'Microsoft' and $mapped_type and $mapped_type != ''">\r
524       <xsl:element name="{$mapped_type}.RenderTransform">\r
525         <xsl:choose>\r
526           <xsl:when test="count(msxsl:node-set($transform_nodes)/*) = 1"><xsl:copy-of select="msxsl:node-set($transform_nodes)" /></xsl:when>\r
527           <xsl:when test="count(msxsl:node-set($transform_nodes)/*) &gt; 1"><TransformGroup><xsl:copy-of select="msxsl:node-set($transform_nodes)" /></TransformGroup></xsl:when>\r
528         </xsl:choose>  \r
529       </xsl:element>\r
530     </xsl:when>\r
531     <xsl:when test="system-property('xsl:vendor') = 'Microsoft'">\r
532       <!-- For instance LinearGradient.Transform -->\r
533       <xsl:choose>\r
534         <xsl:when test="count(msxsl:node-set($transform_nodes)/*) = 1"><xsl:copy-of select="msxsl:node-set($transform_nodes)" /></xsl:when>\r
535         <xsl:when test="count(msxsl:node-set($transform_nodes)/*) &gt; 1"><TransformGroup><xsl:copy-of select="msxsl:node-set($transform_nodes)" /></TransformGroup></xsl:when>\r
536       </xsl:choose>  \r
537     </xsl:when>\r
538   </xsl:choose>  \r
539 </xsl:template>\r
540 \r
541 <xsl:template mode="clip" match="*">\r
542   <xsl:choose>\r
543     <xsl:when test="@clip-path and defs/clipPath/path/@d"><xsl:attribute name="Clip"><xsl:value-of select="defs/clipPath/path/@d" /></xsl:attribute></xsl:when>  \r
544     <xsl:when test="@clip-path and starts-with(@clip-path, 'url(#')"><xsl:attribute name="Clip"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@clip-path, 'url(#'), ')'), '}')" /></xsl:attribute></xsl:when>  \r
545     <xsl:when test="@style and contains(@style, 'clip-path:url(#')"><xsl:attribute name="Clip"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" /></xsl:attribute></xsl:when>  \r
546     <xsl:when test="clipPath"><xsl:apply-templates mode="forward" /></xsl:when>  \r
547   </xsl:choose>\r
548 </xsl:template>\r
549 \r
550 <xsl:template mode="id" match="*">\r
551 <xsl:if test="@id">\r
552   <xsl:attribute name="Name"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>\r
553   <!--\r
554     <xsl:attribute name="x:Key"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>\r
555   -->\r
556 </xsl:if>\r
557 </xsl:template>\r
558 \r
559 <xsl:template match="/">\r
560   <xsl:choose>\r
561     <xsl:when test="$silverlight_compatible = 1">\r
562       <xsl:apply-templates mode="forward" />\r
563     </xsl:when>\r
564     <xsl:otherwise>\r
565       <Viewbox Stretch="Uniform">\r
566         <xsl:apply-templates mode="forward" />\r
567       </Viewbox>\r
568     </xsl:otherwise>   \r
569   </xsl:choose>   \r
570 </xsl:template>\r
571 \r
572 <xsl:template mode="forward" match="defs">\r
573   <xsl:apply-templates mode="forward" />\r
574 </xsl:template>\r
575 \r
576 <xsl:template mode="forward" match="*[name(.) = 'svg' or name(.) = 'g']">\r
577   <xsl:choose>\r
578     <xsl:when test="name(.) = 'svg' or @transform or @viewBox or @id or @clip-path or (@style and contains(@style, 'clip-path:url(#')) or (@width and not(contains(@width, '%'))) or @x or @y or (@height and not(contains(@height, '%'))) or *[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">\r
579       <Canvas>\r
580         <xsl:apply-templates mode="id" select="." />\r
581         <!--\r
582         <xsl:apply-templates mode="clip" select="." />\r
583         -->\r
584         <xsl:if test="@width and not(contains(@width, '%'))"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>\r
585         <xsl:if test="@height and not(contains(@height, '%'))"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>    \r
586         <xsl:if test="@x"><xsl:attribute name="Canvas.Left"><xsl:value-of select="@x" /></xsl:attribute></xsl:if>\r
587         <xsl:if test="@y"><xsl:attribute name="Canvas.Top"><xsl:value-of select="@y" /></xsl:attribute></xsl:if>    \r
588         <xsl:if test="@viewBox">\r
589           <xsl:variable name="viewBox"><xsl:value-of select="normalize-space(translate(@viewBox, ',', ' '))" /></xsl:variable>\r
590           <xsl:attribute name="Width"><xsl:value-of select="substring-before(substring-after(substring-after($viewBox, ' '), ' '), ' ')" /></xsl:attribute>\r
591           <xsl:attribute name="Height"><xsl:value-of select="substring-after(substring-after(substring-after($viewBox, ' '), ' '), ' ')" /></xsl:attribute>\r
592           <Canvas.RenderTransform>\r
593             <TranslateTransform>\r
594               <xsl:attribute name="X"><xsl:value-of select="-number(substring-before($viewBox, ' '))" /></xsl:attribute>\r
595               <xsl:attribute name="Y"><xsl:value-of select="-number(substring-before(substring-after($viewBox, ' '), ' '))" /></xsl:attribute>\r
596             </TranslateTransform>\r
597           </Canvas.RenderTransform>\r
598         </xsl:if>\r
599     <xsl:if test="@transform">\r
600       <Canvas>\r
601         <Canvas.RenderTransform>\r
602           <TransformGroup><xsl:apply-templates mode="transform" select="." /></TransformGroup>\r
603         </Canvas.RenderTransform>\r
604         <xsl:apply-templates mode="forward" select="*" />\r
605       </Canvas>\r
606     </xsl:if>\r
607 \r
608         <xsl:if test="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">\r
609           <Canvas.Resources>\r
610             <xsl:apply-templates mode="forward" select="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']" />\r
611           </Canvas.Resources>\r
612         </xsl:if>\r
613         <xsl:if test="not(@transform)">\r
614           <xsl:apply-templates mode="forward" select="*[name(.) != 'linearGradient' and name(.) != 'radialGradient' and name(.) != 'defs' and name(.) != 'clipPath']" />\r
615         </xsl:if>  \r
616       </Canvas>\r
617     </xsl:when>\r
618     <xsl:when test="not(@transform)">\r
619       <xsl:apply-templates mode="forward" select="*" />\r
620     </xsl:when>\r
621   </xsl:choose>\r
622 </xsl:template>\r
623 \r
624 <xsl:template mode="transform2" match="*">\r
625   <xsl:choose>\r
626     <xsl:when test="@transform">\r
627       <Canvas>\r
628         <Canvas.RenderTransform>\r
629           <TransformGroup><xsl:apply-templates mode="transform" select="." /></TransformGroup>\r
630         </Canvas.RenderTransform>\r
631         <xsl:apply-templates mode="forward" select="." />\r
632       </Canvas>\r
633     </xsl:when>\r
634     <xsl:otherwise>\r
635       <xsl:apply-templates mode="forward" select="." />\r
636     </xsl:otherwise>\r
637   </xsl:choose>\r
638 </xsl:template>\r
639 \r
640 <xsl:template mode="forward" match="*[name(.) = 'image']">\r
641   <Image>\r
642     <xsl:apply-templates mode="id" select="." />\r
643     <xsl:apply-templates mode="clip" select="." />\r
644     <xsl:if test="@xlink:href"><xsl:attribute name="Source"><xsl:value-of select="@xlink:href" /></xsl:attribute></xsl:if>\r
645     <xsl:if test="@width"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>\r
646     <xsl:if test="@height"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>\r
647     <!--xsl:apply-templates mode="transform" /-->\r
648     <xsl:apply-templates mode="forward" />\r
649   </Image>\r
650 </xsl:template>\r
651 \r
652 <xsl:template mode="forward" match="*[name(.) = 'text']">\r
653   <TextBlock>\r
654     <xsl:if test="@font-size"><xsl:attribute name="FontSize"><xsl:value-of select="@font-size" /></xsl:attribute></xsl:if>\r
655     <xsl:if test="@style and contains(@style, 'font-size:')">\r
656       <xsl:variable name="font_size" select="substring-after(@style, 'font-size:')" />\r
657       <xsl:attribute name="FontSize">\r
658         <xsl:choose>\r
659           <xsl:when test="contains($font_size, ';')">\r
660             <xsl:value-of select="substring-before($font_size, ';')" />\r
661           </xsl:when>\r
662           <xsl:otherwise><xsl:value-of select="$font_size" /></xsl:otherwise>\r
663         </xsl:choose>\r
664       </xsl:attribute>  \r
665     </xsl:if>\r
666     <xsl:if test="@font-weight"><xsl:attribute name="FontWeight"><xsl:value-of select="@font-weight" /></xsl:attribute></xsl:if>\r
667     <xsl:if test="@style and contains(@style, 'font-weight:')">\r
668       <xsl:variable name="font_weight" select="substring-after(@style, 'font-weight:')" />\r
669       <xsl:attribute name="FontWeight">\r
670         <xsl:choose>\r
671           <xsl:when test="contains($font_weight, ';')">\r
672             <xsl:value-of select="substring-before($font_weight, ';')" />\r
673           </xsl:when>\r
674           <xsl:otherwise><xsl:value-of select="$font_weight" /></xsl:otherwise>\r
675         </xsl:choose>\r
676       </xsl:attribute>  \r
677     </xsl:if>\r
678     <xsl:if test="@font-family"><xsl:attribute name="FontFamily"><xsl:value-of select="@font-family" /></xsl:attribute></xsl:if>\r
679     <xsl:if test="@style and contains(@style, 'font-family:')">\r
680       <xsl:variable name="font_family" select="substring-after(@style, 'font-family:')" />\r
681       <xsl:attribute name="FontFamily">\r
682         <xsl:choose>\r
683           <xsl:when test="contains($font_family, ';')">\r
684             <xsl:value-of select="substring-before($font_family, ';')" />\r
685           </xsl:when>\r
686           <xsl:otherwise><xsl:value-of select="$font_family" /></xsl:otherwise>\r
687         </xsl:choose>\r
688       </xsl:attribute>  \r
689     </xsl:if>\r
690     <xsl:if test="@font-style"><xsl:attribute name="FontStyle"><xsl:value-of select="@font-style" /></xsl:attribute></xsl:if>\r
691     <xsl:if test="@style and contains(@style, 'font-style:')">\r
692       <xsl:variable name="font_style" select="substring-after(@style, 'font-style:')" />\r
693       <xsl:attribute name="FontStyle">\r
694         <xsl:choose>\r
695           <xsl:when test="contains($font_style, ';')">\r
696             <xsl:value-of select="substring-before($font_style, ';')" />\r
697           </xsl:when>\r
698           <xsl:otherwise><xsl:value-of select="$font_style" /></xsl:otherwise>\r
699         </xsl:choose>\r
700       </xsl:attribute>  \r
701     </xsl:if>\r
702     <xsl:if test="@fill"><xsl:attribute name="Foreground"><xsl:value-of select="@fill" /></xsl:attribute></xsl:if>\r
703     <xsl:if test="@style and contains(@style, 'fill')">\r
704       <xsl:variable name="fill" select="substring-after(@style, 'fill:')" />\r
705       <xsl:attribute name="Foreground">\r
706         <xsl:choose>\r
707           <xsl:when test="contains($fill, ';')">\r
708             <xsl:value-of select="substring-before($fill, ';')" />\r
709           </xsl:when>\r
710           <xsl:otherwise><xsl:value-of select="$fill" /></xsl:otherwise>\r
711         </xsl:choose>\r
712       </xsl:attribute>  \r
713     </xsl:if>\r
714     <xsl:if test="@text-anchor">\r
715       <xsl:attribute name="HorizontalAlignment">\r
716         <xsl:choose>\r
717           <xsl:when test="@text-anchor = 'start'">Left</xsl:when>\r
718           <xsl:when test="@text-anchor = 'middle'">Center</xsl:when>\r
719           <xsl:when test="@text-anchor = 'end'">Right</xsl:when>\r
720         </xsl:choose>\r
721       </xsl:attribute>\r
722     </xsl:if>\r
723     <xsl:if test="@width"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>\r
724     <xsl:if test="@height"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>\r
725     <xsl:if test="@x"><xsl:attribute name="Canvas.Left"><xsl:value-of select="@x" /></xsl:attribute></xsl:if>\r
726     <xsl:if test="@y"><xsl:attribute name="Canvas.Top"><xsl:value-of select="@y" /></xsl:attribute></xsl:if>\r
727     <xsl:apply-templates mode="id" select="." />\r
728     <xsl:apply-templates mode="clip" select="." />\r
729     <!--xsl:apply-templates mode="transform" select="." /-->\r
730     <!--xsl:apply-templates mode="forward" /-->\r
731     <xsl:if test="text()"><xsl:value-of select="text()" /></xsl:if>\r
732     <xsl:if test="*[name(.) = 'tspan']/text()"><xsl:value-of select="*[name(.) = 'tspan']/text()" /></xsl:if>\r
733   </TextBlock>\r
734 </xsl:template>\r
735 \r
736 <xsl:template mode="forward" match="*[name(.) = 'title' or name(.) = 'desc']">\r
737   <!-- -->\r
738 </xsl:template>\r
739 \r
740 <xsl:template mode="forward" match="*[name(.) = 'marker' or name(.) = 'pattern' or name(.) = 'style']">\r
741   <!-- -->\r
742 </xsl:template>\r
743 \r
744 <xsl:template mode="forward" match="*[name(.) = 'symbol']">\r
745   <Style>\r
746     <xsl:if test="@id"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
747     <Canvas>\r
748       <xsl:apply-templates mode="forward" />\r
749     </Canvas>\r
750   </Style>\r
751 </xsl:template>\r
752 \r
753 <xsl:template mode="forward" match="*[name(.) = 'use']">\r
754   <Canvas>\r
755     <xsl:if test="@xlink:href"><xsl:attribute name="Style"><xsl:value-of select="@xlink:href" /></xsl:attribute></xsl:if>\r
756     <!--xsl:apply-templates mode="transform" select="." /-->\r
757     <xsl:apply-templates mode="forward" />\r
758   </Canvas>\r
759 </xsl:template>\r
760 \r
761 <xsl:template mode="forward" match="rdf:RDF | *[name(.) = 'foreignObject']">\r
762   <!-- -->\r
763 </xsl:template>\r
764 \r
765 <xsl:template match="*">\r
766 <xsl:comment><xsl:value-of select="concat('Unknown tag: ', name(.))" /></xsl:comment>\r
767 </xsl:template>\r
768 \r
769 <!-- BRUSHES -->\r
770 \r
771 <xsl:template mode="forward" match="*[name(.) = 'linearGradient']">\r
772   <LinearGradientBrush>\r
773     <xsl:if test="@id"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
774     <xsl:attribute name="MappingMode">\r
775       <xsl:choose>\r
776         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>\r
777         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>\r
778       </xsl:choose>\r
779     </xsl:attribute>\r
780     <xsl:if test="@spreadMethod">\r
781       <xsl:attribute name="SpreadMethod">\r
782         <xsl:choose>\r
783           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>\r
784           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>\r
785           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>\r
786         </xsl:choose>\r
787       </xsl:attribute>\r
788     </xsl:if>\r
789     <xsl:choose>\r
790       <xsl:when test="@x1 and @y1 and @x2 and @y2">\r
791         <xsl:choose>\r
792           <xsl:when test="contains(@x1, '%') and contains(@y1, '%')">\r
793             <xsl:attribute name="StartPoint"><xsl:value-of select="concat(substring-before(@x1, '%') div 100, ',', substring-before(@y1,'%') div 100)" /></xsl:attribute>\r
794           </xsl:when>\r
795           <xsl:otherwise>\r
796             <xsl:attribute name="StartPoint"><xsl:value-of select="concat(@x1, ',', @y1)" /></xsl:attribute>\r
797           </xsl:otherwise>\r
798         </xsl:choose>  \r
799         <xsl:choose>\r
800           <xsl:when test="contains(@x2, '%') and contains(@y2, '%')">\r
801             <xsl:attribute name="EndPoint"><xsl:value-of select="concat(substring-before(@x2, '%') div 100, ',', substring-before(@y2,'%') div 100)" /></xsl:attribute>\r
802           </xsl:when>\r
803           <xsl:otherwise>\r
804             <xsl:attribute name="EndPoint"><xsl:value-of select="concat(@x2, ',', @y2)" /></xsl:attribute>\r
805           </xsl:otherwise>\r
806         </xsl:choose>  \r
807       </xsl:when>\r
808       <xsl:otherwise>\r
809         <xsl:attribute name="StartPoint"><xsl:value-of select="'0,0'" /></xsl:attribute>\r
810         <xsl:attribute name="EndPoint"><xsl:value-of select="'1,1'" /></xsl:attribute>\r
811       </xsl:otherwise>\r
812     </xsl:choose>\r
813     <LinearGradientBrush.GradientStops>\r
814       <GradientStopCollection>\r
815         <xsl:choose>\r
816           <xsl:when test="@xlink:href">\r
817             <xsl:variable name="reference_id" select="@xlink:href" />\r
818             <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />\r
819           </xsl:when>\r
820           <xsl:otherwise><xsl:apply-templates mode="forward" /></xsl:otherwise>  \r
821         </xsl:choose>  \r
822       </GradientStopCollection>\r
823     </LinearGradientBrush.GradientStops>\r
824     <xsl:if test="@gradientTransform">\r
825     <LinearGradientBrush.Transform>\r
826       <xsl:apply-templates mode="transform" select="." />\r
827     </LinearGradientBrush.Transform>\r
828   </xsl:if>  \r
829   </LinearGradientBrush>\r
830 </xsl:template>\r
831 \r
832 <xsl:template mode="forward" match="*[name(.) = 'radialGradient']">\r
833   <RadialGradientBrush>\r
834     <xsl:if test="@id"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
835     <xsl:attribute name="MappingMode">\r
836       <xsl:choose>\r
837         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>\r
838         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>\r
839       </xsl:choose>\r
840     </xsl:attribute>\r
841     <xsl:if test="@spreadMethod">\r
842       <xsl:attribute name="SpreadMethod">\r
843         <xsl:choose>\r
844           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>\r
845           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>\r
846           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>\r
847         </xsl:choose>\r
848       </xsl:attribute>\r
849     </xsl:if>\r
850     <xsl:if test="@cx and @cy">\r
851       <xsl:attribute name="Center">\r
852         <xsl:choose>\r
853           <xsl:when test="contains(@cx, '%') and contains(@cy, '%')">\r
854             <xsl:value-of select="concat(number(substring-before(@cx, '%')) div 100, ',', number(substring-before(@cy, '%')) div 100)" />\r
855           </xsl:when>  \r
856           <xsl:otherwise>\r
857             <xsl:value-of select="concat(@cx, ',', @cy)" />\r
858           </xsl:otherwise>  \r
859         </xsl:choose>\r
860       </xsl:attribute>\r
861     </xsl:if>  \r
862     <xsl:if test="@fx and @fy">\r
863       <xsl:attribute name="GradientOrigin">\r
864         <xsl:choose>\r
865           <xsl:when test="contains(@fx, '%') and contains(@fy, '%')">\r
866             <xsl:value-of select="concat(number(substring-before(@fx, '%')) div 100, ',', number(substring-before(@fy, '%')) div 100)" />\r
867           </xsl:when>  \r
868           <xsl:otherwise>\r
869             <xsl:value-of select="concat(@fx, ',', @fy)" />\r
870           </xsl:otherwise>  \r
871         </xsl:choose>\r
872       </xsl:attribute>\r
873     </xsl:if>  \r
874     <xsl:if test="@r">\r
875       <xsl:choose>\r
876         <xsl:when test="contains(@r, '%')">\r
877           <xsl:attribute name="RadiusX"><xsl:value-of select="number(substring-before(@r, '%')) div 100" /></xsl:attribute>\r
878           <xsl:attribute name="RadiusY"><xsl:value-of select="number(substring-before(@r, '%')) div 100" /></xsl:attribute>\r
879         </xsl:when>  \r
880         <xsl:otherwise>\r
881           <xsl:attribute name="RadiusX"><xsl:value-of select="@r" /></xsl:attribute>\r
882           <xsl:attribute name="RadiusY"><xsl:value-of select="@r" /></xsl:attribute>\r
883         </xsl:otherwise>  \r
884       </xsl:choose>\r
885     </xsl:if>  \r
886     <RadialGradientBrush.GradientStops>\r
887       <GradientStopCollection>\r
888         <xsl:choose>\r
889           <xsl:when test="@xlink:href">\r
890             <xsl:variable name="reference_id" select="@xlink:href" />\r
891             <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />\r
892           </xsl:when>\r
893           <xsl:otherwise><xsl:apply-templates mode="forward" /></xsl:otherwise>\r
894         </xsl:choose>\r
895       </GradientStopCollection>\r
896     </RadialGradientBrush.GradientStops>\r
897     <xsl:if test="@gradientTransform">\r
898     <RadialGradientBrush.Transform>\r
899       <xsl:apply-templates mode="transform" select="." />\r
900     </RadialGradientBrush.Transform>\r
901     </xsl:if>  \r
902   </RadialGradientBrush>\r
903 </xsl:template>\r
904 \r
905 <xsl:template mode="forward" match="*[name(.) = 'stop']">\r
906   <GradientStop>\r
907     <!--xsl:apply-templates mode="stop_opacity" select="." /-->\r
908     <xsl:apply-templates mode="stop_color" select="." />\r
909     <xsl:apply-templates mode="offset" select="." />\r
910     <xsl:apply-templates mode="forward" />\r
911   </GradientStop>\r
912 </xsl:template>\r
913 \r
914 <!-- SHAPES -->\r
915 \r
916 <xsl:template mode="forward" match="*[name(.) = 'line']">\r
917   <Line>\r
918     <xsl:if test="@x1"><xsl:attribute name="X1"><xsl:value-of select="@x1" /></xsl:attribute></xsl:if> \r
919     <xsl:if test="@y1"><xsl:attribute name="Y1"><xsl:value-of select="@y1" /></xsl:attribute></xsl:if> \r
920     <xsl:if test="@x2"><xsl:attribute name="X2"><xsl:value-of select="@x2" /></xsl:attribute></xsl:if> \r
921     <xsl:if test="@y2"><xsl:attribute name="Y2"><xsl:value-of select="@y2" /></xsl:attribute></xsl:if>\r
922     <xsl:apply-templates mode="id" select="." />\r
923     <xsl:apply-templates mode="template_fill" select="." />\r
924     <xsl:apply-templates mode="template_stroke" select="." />\r
925     <xsl:apply-templates mode="stroke_width" select="." />\r
926     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
927     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
928     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
929     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
930     <xsl:apply-templates mode="stroke_linecap" select="." />\r
931     \r
932     <xsl:apply-templates mode="transform" select=".">\r
933       <xsl:with-param name="mapped_type" select="'Line'" />\r
934     </xsl:apply-templates>    \r
935     \r
936     <xsl:apply-templates mode="forward" />\r
937   </Line>\r
938 </xsl:template>\r
939 \r
940 <xsl:template mode="forward" match="*[name(.) = 'rect']">\r
941   <Rectangle>\r
942     <xsl:if test="@x"><xsl:attribute name="Canvas.Left"><xsl:value-of select="@x" /></xsl:attribute></xsl:if>  \r
943     <xsl:if test="@y"><xsl:attribute name="Canvas.Top"><xsl:value-of select="@y" /></xsl:attribute></xsl:if>  \r
944     <xsl:if test="@width"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>  \r
945     <xsl:if test="@height"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>  \r
946     <xsl:if test="@rx"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>  \r
947     <xsl:if test="@ry"><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>\r
948     <xsl:if test="@rx and not(@ry)"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute><xsl:attribute name="RadiusY"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>\r
949     <xsl:if test="@ry and not(@rx)"><xsl:attribute name="RadiusX"><xsl:value-of select="@ry" /></xsl:attribute><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>\r
950     <xsl:apply-templates mode="id" select="." />\r
951     <xsl:apply-templates mode="template_fill" select="." />\r
952     <xsl:apply-templates mode="template_stroke" select="." />\r
953     <xsl:apply-templates mode="stroke_width" select="." />\r
954     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
955     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
956     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
957     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
958     <xsl:apply-templates mode="stroke_linecap" select="." />\r
959     \r
960     <xsl:apply-templates mode="resources" select="." />\r
961     \r
962     <xsl:apply-templates mode="clip" select="." />\r
963     \r
964     <xsl:apply-templates mode="transform" select=".">\r
965       <xsl:with-param name="mapped_type" select="'Rectangle'" />\r
966     </xsl:apply-templates>    \r
967     \r
968     <xsl:apply-templates mode="forward" />\r
969   </Rectangle>\r
970 </xsl:template>\r
971 \r
972 <xsl:template mode="forward" match="*[name(.) = 'polygon']">\r
973   <Polygon>\r
974     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>\r
975     <xsl:apply-templates mode="id" select="." />\r
976     <xsl:apply-templates mode="fill_rule" select="." />\r
977     <xsl:apply-templates mode="template_fill" select="." />\r
978     <xsl:apply-templates mode="template_stroke" select="." />\r
979     <xsl:apply-templates mode="stroke_width" select="." />\r
980     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
981     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
982     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
983     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
984     <xsl:apply-templates mode="stroke_linecap" select="." />\r
985     \r
986     <xsl:apply-templates mode="transform" select=".">\r
987       <xsl:with-param name="mapped_type" select="'Polygon'" />\r
988     </xsl:apply-templates>    \r
989     \r
990     <xsl:apply-templates mode="forward" />\r
991   </Polygon>\r
992 </xsl:template>\r
993 \r
994 <xsl:template mode="forward" match="*[name(.) = 'polyline']">\r
995   <Polyline>\r
996     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>\r
997     <xsl:apply-templates mode="id" select="." />\r
998     <xsl:apply-templates mode="fill_rule" select="." />\r
999     <xsl:apply-templates mode="template_fill" select="." />\r
1000     <xsl:apply-templates mode="template_stroke" select="." />\r
1001     <xsl:apply-templates mode="stroke_width" select="." />\r
1002     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1003     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1004     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1005     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1006     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1007     \r
1008     <xsl:apply-templates mode="transform" select=".">\r
1009       <xsl:with-param name="mapped_type" select="'Polyline'" />\r
1010     </xsl:apply-templates>    \r
1011     \r
1012     <xsl:apply-templates mode="forward" />\r
1013   </Polyline>\r
1014 </xsl:template>\r
1015 \r
1016 <xsl:template mode="forward" match="*[name(.) = 'path']">\r
1017   <Path>\r
1018     <xsl:apply-templates mode="id" select="." />\r
1019     <xsl:apply-templates mode="template_fill" select="." />\r
1020     <xsl:apply-templates mode="template_stroke" select="." />\r
1021     <xsl:apply-templates mode="stroke_width" select="." />\r
1022     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1023     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1024     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1025     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1026     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1027     <xsl:if test="@d">\r
1028       <xsl:choose>\r
1029         <xsl:when test="$silverlight_compatible = 1">\r
1030           <xsl:attribute name="Data">\r
1031             <xsl:value-of select="translate(@d , ',', ' ')" />\r
1032           </xsl:attribute>\r
1033         </xsl:when>\r
1034         <xsl:otherwise>\r
1035           <Path.Data>\r
1036             <PathGeometry>\r
1037               <xsl:attribute name="Figures">\r
1038                 <xsl:value-of select="translate(@d , ',', ' ')" />\r
1039               </xsl:attribute>\r
1040               <xsl:apply-templates mode="fill_rule" select="." />\r
1041             </PathGeometry>  \r
1042           </Path.Data>\r
1043          </xsl:otherwise>   \r
1044       </xsl:choose>   \r
1045     </xsl:if>\r
1046     \r
1047     <xsl:apply-templates mode="transform" select=".">\r
1048       <xsl:with-param name="mapped_type" select="'Path'" />\r
1049     </xsl:apply-templates>\r
1050     \r
1051     <xsl:apply-templates mode="forward" />\r
1052   </Path>\r
1053 </xsl:template>\r
1054 \r
1055 <xsl:template mode="forward" match="*[name(.) = 'ellipse']">\r
1056   <Ellipse>\r
1057     <xsl:variable name="cx">\r
1058       <xsl:choose>\r
1059         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>\r
1060         <xsl:otherwise>0</xsl:otherwise>\r
1061       </xsl:choose>  \r
1062     </xsl:variable>\r
1063     <xsl:variable name="cy">\r
1064       <xsl:choose>\r
1065         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>\r
1066         <xsl:otherwise>0</xsl:otherwise>\r
1067       </xsl:choose>  \r
1068     </xsl:variable>\r
1069     <xsl:if test="@rx">\r
1070       <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @rx, "#.#")' /></xsl:attribute>\r
1071       <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @rx, "#.#")' /></xsl:attribute>\r
1072     </xsl:if>\r
1073     <xsl:if test="@ry">\r
1074       <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @ry, "#.#")' /></xsl:attribute>\r
1075       <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @ry, "#.#")' /></xsl:attribute>\r
1076     </xsl:if>\r
1077     <xsl:apply-templates mode="id" select="." />\r
1078     <xsl:apply-templates mode="template_fill" select="." />\r
1079     <xsl:apply-templates mode="template_stroke" select="." />\r
1080     <xsl:apply-templates mode="stroke_width" select="." />\r
1081     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1082     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1083     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1084     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1085     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1086     \r
1087     <xsl:apply-templates mode="clip" select="." />\r
1088     \r
1089     <xsl:apply-templates mode="transform" select=".">\r
1090       <xsl:with-param name="mapped_type" select="'Ellipse'" />\r
1091     </xsl:apply-templates>\r
1092     \r
1093     <xsl:apply-templates mode="forward" />\r
1094   </Ellipse>\r
1095 </xsl:template>\r
1096 \r
1097 <xsl:template mode="forward" match="*[name(.) = 'circle']">\r
1098   <Ellipse>\r
1099     <xsl:variable name="cx">\r
1100       <xsl:choose>\r
1101         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>\r
1102         <xsl:otherwise>0</xsl:otherwise>\r
1103       </xsl:choose>  \r
1104     </xsl:variable>\r
1105     <xsl:variable name="cy">\r
1106       <xsl:choose>\r
1107         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>\r
1108         <xsl:otherwise>0</xsl:otherwise>\r
1109       </xsl:choose>  \r
1110     </xsl:variable>\r
1111     <xsl:if test="@r">\r
1112        <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @r, "#.#")' /></xsl:attribute>
1113        <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @r, "#.#")' /></xsl:attribute>
1114        <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>
1115        <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>       \r
1116     </xsl:if>\r
1117     <xsl:apply-templates mode="id" select="." />\r
1118     <xsl:apply-templates mode="template_fill" select="." />\r
1119     <xsl:apply-templates mode="template_stroke" select="." />\r
1120     <xsl:apply-templates mode="stroke_width" select="." />\r
1121     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1122     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1123     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1124     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1125     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1126     \r
1127     <xsl:apply-templates mode="clip" select="." />\r
1128     \r
1129     <xsl:apply-templates mode="transform" select=".">\r
1130       <xsl:with-param name="mapped_type" select="'Ellipse'" />\r
1131     </xsl:apply-templates>\r
1132     \r
1133     <xsl:apply-templates mode="forward" />\r
1134   </Ellipse>\r
1135 </xsl:template>\r
1136 \r
1137 <xsl:template mode="forward" match="*[name(.) = 'clipPath']">\r
1138   <xsl:apply-templates mode="geometry" />\r
1139 </xsl:template>\r
1140 \r
1141 <xsl:template mode="geometry" match="*[name(.) = 'circle']">\r
1142   <EllipseGeometry>\r
1143     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>  \r
1144     <xsl:if test="@cx and @cy"><xsl:attribute name="Center"><xsl:value-of select="concat(@cx, ',', @cy)" /></xsl:attribute></xsl:if>\r
1145     <xsl:if test="@r">\r
1146       <xsl:attribute name="RadiusX"><xsl:value-of select="@r" /></xsl:attribute>\r
1147       <xsl:attribute name="RadiusY"><xsl:value-of select="@r" /></xsl:attribute>\r
1148     </xsl:if>\r
1149   </EllipseGeometry>\r
1150 </xsl:template>\r
1151 \r
1152 <xsl:template mode="geometry" match="*[name(.) = 'rect']">\r
1153   <RectangleGeometry>\r
1154     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>  \r
1155     <!--\r
1156     <xsl:if test="@x"><xsl:attribute name="Canvas.Left"><xsl:value-of select="@x" /></xsl:attribute></xsl:if>  \r
1157     <xsl:if test="@y"><xsl:attribute name="Canvas.Top"><xsl:value-of select="@y" /></xsl:attribute></xsl:if>  \r
1158     <xsl:if test="@width"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>  \r
1159     <xsl:if test="@height"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>  \r
1160     <xsl:if test="@rx"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>  \r
1161     <xsl:if test="@ry"><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>  \r
1162     -->\r
1163     <xsl:attribute name="Rect"><xsl:value-of select="concat('0, 0, ', @width, ', ', @height)" /></xsl:attribute>\r
1164   </RectangleGeometry>\r
1165 </xsl:template>\r
1166 \r
1167 </xsl:stylesheet>\r