Code

a21da1290938d6232f734d7a9b2c750d54a2c2ec
[inkscape.git] / share / extensions / svg2xaml.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
3 <!--
4 Copyright (c) 2005-2007 authors:
5 Original version: Toine de Greef (a.degreef@chello.nl)
6 Modified (2010-2011) by Nicolas Dufour (nicoduf@yahoo.fr) (blur support, units
7 convertion, comments, and some other fixes)
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -->
28 <xsl:stylesheet version="1.0"
29 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
30 xmlns:xlink="http://www.w3.org/1999/xlink"
31 xmlns:xs="http://www.w3.org/2001/XMLSchema"
32 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
33 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
34 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
35 xmlns:exsl="http://exslt.org/common"
36 xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"
37 exclude-result-prefixes="rdf xlink xs exsl libxslt">
39 <xsl:strip-space elements="*" />
40 <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
42 <xsl:param name="silverlight_compatible" select="1" />
44 <!-- 
45   // Containers //
47   * Root templace
48   * Groups
49 -->
51 <!-- 
52   // Root template //
53 -->
54 <xsl:template match="/">
55   <xsl:choose>
56     <xsl:when test="$silverlight_compatible = 1">
57       <xsl:apply-templates mode="forward" />
58     </xsl:when>
59     <xsl:otherwise>
60       <Viewbox Stretch="Uniform">
61         <xsl:apply-templates mode="forward" />
62       </Viewbox>
63     </xsl:otherwise>   
64   </xsl:choose>
65 </xsl:template>
67 <!-- 
68   // SVG and groups //  
69   (including layers)
70 -->
71 <xsl:template mode="forward" match="*[name(.) = 'svg' or name(.) = 'g']">
72   <xsl:choose>
73     <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']">
74       <Canvas>
75         <xsl:apply-templates mode="id" select="." />
76         <!--
77         <xsl:apply-templates mode="clip" select="." />
78         -->
79         <xsl:if test="@style and contains(@style, 'display:none')">
80           <xsl:attribute name="Visibility">Collapsed</xsl:attribute>
81         </xsl:if>
82         <xsl:if test="@style and contains(@style, 'opacity:')">
83           <xsl:attribute name="Opacity">
84             <xsl:choose>
85               <xsl:when test="contains(substring-after(@style, 'opacity:'), ';')">
86                 <xsl:value-of select="substring-before(substring-after(@style, 'opacity:'), ';')" />
87               </xsl:when>
88               <xsl:otherwise>
89                 <xsl:value-of select="substring-after(@style, 'opacity:')" />
90               </xsl:otherwise>
91             </xsl:choose>
92           </xsl:attribute>
93         </xsl:if>
94         <xsl:if test="@width and not(contains(@width, '%'))">
95           <xsl:attribute name="Width">
96             <xsl:call-template name="convert_unit">
97               <xsl:with-param name="convert_value" select="@width" />
98             </xsl:call-template>
99           </xsl:attribute>
100         </xsl:if>
101           <xsl:if test="@height and not(contains(@height, '%'))">
102           <xsl:attribute name="Height">
103             <xsl:call-template name="convert_unit">
104               <xsl:with-param name="convert_value" select="@height" />
105             </xsl:call-template>
106           </xsl:attribute>
107         </xsl:if>
108         <xsl:if test="@x">
109           <xsl:attribute name="Canvas.Left">
110             <xsl:call-template name="convert_unit">
111               <xsl:with-param name="convert_value" select="@x" />
112             </xsl:call-template>
113           </xsl:attribute></xsl:if>
114         <xsl:if test="@y">
115           <xsl:attribute name="Canvas.Top">
116             <xsl:call-template name="convert_unit">
117               <xsl:with-param name="convert_value" select="@y" />
118             </xsl:call-template>
119           </xsl:attribute>
120         </xsl:if>
121         <xsl:if test="@viewBox">
122           <xsl:variable name="viewBox">
123             <xsl:value-of select="normalize-space(translate(@viewBox, ',', ' '))" />
124           </xsl:variable>
125           <xsl:attribute name="Width">
126             <xsl:value-of select="substring-before(substring-after(substring-after($viewBox, ' '), ' '), ' ')" />
127           </xsl:attribute>
128           <xsl:attribute name="Height">
129             <xsl:value-of select="substring-after(substring-after(substring-after($viewBox, ' '), ' '), ' ')" />
130           </xsl:attribute>
131           <Canvas.RenderTransform>
132             <TranslateTransform>
133               <xsl:attribute name="X">
134                 <xsl:value-of select="-number(substring-before($viewBox, ' '))" />
135               </xsl:attribute>
136               <xsl:attribute name="Y">
137                 <xsl:value-of select="-number(substring-before(substring-after($viewBox, ' '), ' '))" />
138               </xsl:attribute>
139             </TranslateTransform>
140           </Canvas.RenderTransform>
141         </xsl:if>
142         <xsl:if test="@transform">
143           <Canvas>
144             <Canvas.RenderTransform>
145               <TransformGroup>
146                 <xsl:apply-templates mode="transform" select="." />
147               </TransformGroup>
148             </Canvas.RenderTransform>
149             <xsl:apply-templates mode="forward" select="*" />
150           </Canvas>
151         </xsl:if>
153         <xsl:if test="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">
154           <Canvas.Resources>
155             <xsl:apply-templates mode="forward" select="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']" />
156           </Canvas.Resources>
157         </xsl:if>
158         <xsl:if test="not(@transform)">
159           <xsl:apply-templates mode="forward" select="*[name(.) != 'linearGradient' and name(.) != 'radialGradient' and name(.) != 'defs' and name(.) != 'clipPath']" />
160         </xsl:if>  
161       </Canvas>
162     </xsl:when>
163     <xsl:when test="not(@transform)">
164       <xsl:apply-templates mode="forward" select="*" />
165     </xsl:when>
166   </xsl:choose>
167 </xsl:template>
169 <!-- 
170   // Transforms //
171   All the matrix, translate, rotate... stuff.
172   Fixme: XAML transforms don't show the same result as SVG ones with the same values.
174   * Parse transform
175   * Apply transform
176 -->
178 <!-- 
179   // Parse transform //
180 -->
181 <xsl:template name="parse_transform">
182   <xsl:param name="input" />
183   <xsl:choose>
184   
185     <!-- Matrix transform -->
186     <xsl:when test="starts-with($input, 'matrix(')">
187       <MatrixTransform>
188         <xsl:attribute name="Matrix">
189           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'matrix('), ')'), ',', ' '))" />
190         </xsl:attribute>
191       </MatrixTransform>
192       <xsl:call-template name="parse_transform">
193         <xsl:with-param name="input" select="substring-after($input, ') ')" />
194       </xsl:call-template>      
195     </xsl:when>
196     
197     <!-- Scale transform -->
198     <xsl:when test="starts-with($input, 'scale(')">
199       <ScaleTransform>
200         <xsl:variable name="scale" select="normalize-space(translate(substring-before(substring-after($input, 'scale('), ')'), ',', ' '))" />
201         <xsl:choose>
202           <xsl:when test="contains($scale, ' ')">
203             <xsl:attribute name="ScaleX">
204               <xsl:value-of select="substring-before($scale, ' ')" />
205             </xsl:attribute>
206             <xsl:attribute name="ScaleY">
207               <xsl:value-of select="substring-after($scale, ' ')" />
208             </xsl:attribute>
209           </xsl:when>
210           <xsl:otherwise>
211             <xsl:attribute name="ScaleX">
212               <xsl:value-of select="$scale" />
213             </xsl:attribute>
214             <xsl:attribute name="ScaleY">
215               <xsl:value-of select="$scale" />
216             </xsl:attribute>
217           </xsl:otherwise>
218         </xsl:choose>
219       </ScaleTransform>
220       <xsl:call-template name="parse_transform">
221         <xsl:with-param name="input" select="substring-after($input, ') ')" />
222       </xsl:call-template>
223     </xsl:when>
224     
225     <!-- Rotate transform -->
226     <xsl:when test="starts-with($input, 'rotate(')">
227       <RotateTransform>
228         <xsl:attribute name="Angle">
229           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'rotate('), ')'), ',', ' '))" />
230         </xsl:attribute>
231         <xsl:if test="@rx">
232           <xsl:attribute name="CenterX">
233             <xsl:value-of select="@rx" />
234           </xsl:attribute>
235         </xsl:if>
236         <xsl:if test="@ry">
237           <xsl:attribute name="CenterY">
238             <xsl:value-of select="@ry" />
239           </xsl:attribute>
240         </xsl:if>
241       </RotateTransform>
242       <xsl:call-template name="parse_transform">
243         <xsl:with-param name="input" select="substring-after($input, ') ')" />
244       </xsl:call-template>
245     </xsl:when>
246     
247     <!-- Skew transform -->
248     <xsl:when test="starts-with($input, 'skewX(')">
249       <SkewTransform>
250         <xsl:attribute name="AngleX">
251           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'skewX('), ')'), ',', ' '))" />
252         </xsl:attribute>
253         <xsl:call-template name="parse_transform">
254           <xsl:with-param name="input" select="substring-after($input, ') ')" />
255         </xsl:call-template>
256       </SkewTransform>
257     </xsl:when>
258     <xsl:when test="starts-with($input, 'skewY(')">
259       <SkewTransform>
260         <xsl:attribute name="AngleY">
261           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'skewY('), ')'), ',', ' '))" />
262         </xsl:attribute>
263         <xsl:call-template name="parse_transform">
264           <xsl:with-param name="input" select="substring-after($input, ') ')" />
265         </xsl:call-template>
266       </SkewTransform>
267     </xsl:when>
268     
269     <!-- Translate transform -->
270     <xsl:when test="starts-with($input, 'translate(')">
271       <TranslateTransform>
272       <xsl:variable name="translate" select="normalize-space(translate(substring-before(substring-after($input, 'translate('), ')'), ',', ' '))" />
273         <xsl:choose>
274           <xsl:when test="contains($translate, ' ')">
275             <xsl:attribute name="X">
276               <xsl:value-of select="substring-before($translate, ' ')" />
277             </xsl:attribute>
278             <xsl:attribute name="Y">
279               <xsl:value-of select="substring-after($translate, ' ')" />
280             </xsl:attribute>
281           </xsl:when>
282           <xsl:otherwise>
283             <xsl:attribute name="X">
284               <xsl:value-of select="$translate" />
285             </xsl:attribute>
286           </xsl:otherwise>
287         </xsl:choose>
288       </TranslateTransform>
289       <xsl:call-template name="parse_transform">
290         <xsl:with-param name="input" select="substring-after($input, ') ')" />
291       </xsl:call-template>
292     </xsl:when>
293   </xsl:choose>
294 </xsl:template>
296 <!-- 
297   // Apply transform //
298 -->
299 <xsl:template mode="transform" match="*">
300   <xsl:param name="mapped_type" />
301   <xsl:if test="@transform or @gradientTransform">
302     <xsl:variable name="transform">
303       <xsl:choose>
304         <xsl:when test="@transform">
305           <xsl:value-of select="@transform" />
306         </xsl:when>
307         <xsl:otherwise>
308           <xsl:value-of select="@gradientTransform" />
309         </xsl:otherwise>
310       </xsl:choose>
311     </xsl:variable>
312     <xsl:variable name="transform_nodes">
313       <xsl:call-template name="parse_transform">
314         <xsl:with-param name="input" select="$transform" />
315       </xsl:call-template>
316     </xsl:variable>
318     <xsl:choose>
319       <xsl:when test="$mapped_type and $mapped_type != ''">
320         <xsl:element name="{$mapped_type}.RenderTransform">
321           <xsl:choose>
322             <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1">
323               <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
324             </xsl:when>
325             <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1">
326               <TransformGroup>
327                 <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
328               </TransformGroup>
329             </xsl:when>
330           </xsl:choose>
331         </xsl:element>
332       </xsl:when>
333       <xsl:otherwise>
334         <!-- For instance LinearGradient.Transform -->
335         <xsl:choose>
336           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1">
337             <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
338           </xsl:when>
339           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1">
340             <TransformGroup>
341               <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
342             </TransformGroup>
343           </xsl:when>
344         </xsl:choose>
345       </xsl:otherwise>
346     </xsl:choose>
347   </xsl:if>  
348 </xsl:template>
350 <!--
351   // Resources (defs) //
353   * Resources ids
354   * Generic defs template
355   * Generic filters template
356   * Filter effects
357   * Linked filter effects
358   * Linear gradients
359   * Radial gradients
360   * Generic gradient stops
361   * Clipping
362 -->
364 <!-- 
365   // Resources ids //
366 -->
367 <xsl:template mode="resources" match="*">
368   <!-- should be in-depth -->
369   <xsl:if test="ancestor::*[name(.) = 'defs']"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>
370 </xsl:template>
372 <!--
373   // Generic defs template //
374 -->
375 <xsl:template mode="forward" match="*[name(.) = 'defs']">
376   <xsl:apply-templates mode="forward" />
377 </xsl:template>
379 <!--
380   // Generic filters template //
381   Limited to one filter (can be improved)
382 -->
383 <xsl:template mode="forward" match="*[name(.) = 'filter']">
384     <xsl:if test="count(*) = 1">
385       <xsl:apply-templates mode="forward" />
386     </xsl:if> 
387 </xsl:template>
389 <!--
390   // GaussianBlur filter effects //
391   Blur values approximated with d = floor(s * 3*sqrt(2*pi)/4 + 0.5) from:
392     http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
393     
394   Not supported by XAML:
395   * Horizontal and vertical blur.
396 -->
397 <xsl:template mode="forward" match="*[name(.) = 'feGaussianBlur']">
398   <BlurEffect>
399     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>
400     <xsl:if test="@stdDeviation">
401       <xsl:variable name="blur" select="normalize-space(translate(@stdDeviation, ',', ' '))" />
402       <xsl:choose>
403         <xsl:when test="not(contains($blur, ' '))">
404           <xsl:attribute name="Radius">
405             <xsl:value-of select="floor($blur * 1.88 + 0.5)" />
406           </xsl:attribute>
407         </xsl:when>
408         <xsl:otherwise>
409           <xsl:attribute name="Radius">
410             <xsl:value-of select="floor(substring-before($blur, ' ') * 1.88 + 0.5)" />
411           </xsl:attribute>
412         </xsl:otherwise>
413       </xsl:choose>          
414     </xsl:if>
415   </BlurEffect>  
416 </xsl:template>
418 <!--
419   // Linked filter effect //
420   Only supports blurs
421 -->
422 <xsl:template mode="filter_effect" match="*">
423   <xsl:choose>
424     <xsl:when test="@filter and starts-with(@filter, 'url(#')">
425       <xsl:attribute name="Effect">
426         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@filter, 'url(#'), ')'), '}')" />
427       </xsl:attribute>
428     </xsl:when>
429     <xsl:when test="@style and contains(@style, 'filter:url(#')">
430       <xsl:attribute name="Effect">
431         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'filter:url(#'), ')'), '}')" />
432       </xsl:attribute>
433     </xsl:when>
434   </xsl:choose>
435 </xsl:template>
437 <!--
438   // Linear gradient //
439 -->
440 <xsl:template mode="forward" match="*[name(.) = 'linearGradient']">
441   <LinearGradientBrush>
442     <xsl:if test="@id">
443       <xsl:attribute name="x:Key">
444         <xsl:value-of select="@id" />
445       </xsl:attribute>
446     </xsl:if>
447     <xsl:attribute name="MappingMode">
448       <xsl:choose>
449         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>
450         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>
451       </xsl:choose>
452     </xsl:attribute>
453     <xsl:if test="@spreadMethod">
454       <xsl:attribute name="SpreadMethod">
455         <xsl:choose>
456           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>
457           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>
458           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>
459         </xsl:choose>
460       </xsl:attribute>
461     </xsl:if>
462     <xsl:choose>
463       <xsl:when test="@x1 and @y1 and @x2 and @y2">
464         <xsl:choose>
465           <xsl:when test="contains(@x1, '%') and contains(@y1, '%')">
466             <xsl:attribute name="StartPoint">
467               <xsl:value-of select="concat(substring-before(@x1, '%') div 100, ',', substring-before(@y1,'%') div 100)" />
468             </xsl:attribute>
469           </xsl:when>
470           <xsl:otherwise>
471             <xsl:attribute name="StartPoint">
472               <xsl:value-of select="concat(@x1, ',', @y1)" />
473             </xsl:attribute>
474           </xsl:otherwise>
475         </xsl:choose>
476         <xsl:choose>
477           <xsl:when test="contains(@x2, '%') and contains(@y2, '%')">
478             <xsl:attribute name="EndPoint">
479               <xsl:value-of select="concat(substring-before(@x2, '%') div 100, ',', substring-before(@y2,'%') div 100)" />
480             </xsl:attribute>
481           </xsl:when>
482           <xsl:otherwise>
483             <xsl:attribute name="EndPoint">
484               <xsl:value-of select="concat(@x2, ',', @y2)" />
485             </xsl:attribute>
486           </xsl:otherwise>
487         </xsl:choose>  
488       </xsl:when>
489       <xsl:otherwise>
490         <xsl:attribute name="StartPoint">
491           <xsl:value-of select="'0,0'" />
492         </xsl:attribute>
493         <xsl:attribute name="EndPoint">
494           <xsl:value-of select="'1,1'" />
495         </xsl:attribute>
496       </xsl:otherwise>
497     </xsl:choose>
498     <LinearGradientBrush.GradientStops>
499       <GradientStopCollection>
500         <xsl:choose>
501           <xsl:when test="@xlink:href">
502             <xsl:variable name="reference_id" select="@xlink:href" />
503             <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />
504           </xsl:when>
505           <xsl:otherwise>
506             <xsl:apply-templates mode="forward" />
507           </xsl:otherwise>
508         </xsl:choose>
509       </GradientStopCollection>
510     </LinearGradientBrush.GradientStops>
511     <xsl:if test="@gradientTransform">
512       <LinearGradientBrush.Transform>
513         <xsl:apply-templates mode="transform" select="." />
514       </LinearGradientBrush.Transform>
515     </xsl:if>
516   </LinearGradientBrush>
517 </xsl:template>
519 <!--
520   // Radial gradient //
521 -->
522 <xsl:template mode="forward" match="*[name(.) = 'radialGradient']">
523   <RadialGradientBrush>
524     <xsl:if test="@id">
525       <xsl:attribute name="x:Key">
526         <xsl:value-of select="@id" />
527       </xsl:attribute>
528     </xsl:if>
529     <xsl:attribute name="MappingMode">
530       <xsl:choose>
531         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>
532         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>
533       </xsl:choose>
534     </xsl:attribute>
535     <xsl:if test="@spreadMethod">
536       <xsl:attribute name="SpreadMethod">
537         <xsl:choose>
538           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>
539           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>
540           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>
541         </xsl:choose>
542       </xsl:attribute>
543     </xsl:if>
544     <xsl:if test="@cx and @cy">
545       <xsl:attribute name="Center">
546         <xsl:choose>
547           <xsl:when test="contains(@cx, '%') and contains(@cy, '%')">
548             <xsl:value-of select="concat(number(substring-before(@cx, '%')) div 100, ',', number(substring-before(@cy, '%')) div 100)" />
549           </xsl:when>
550           <xsl:otherwise>
551             <xsl:value-of select="concat(@cx, ',', @cy)" />
552           </xsl:otherwise>
553         </xsl:choose>
554       </xsl:attribute>
555     </xsl:if>  
556     <xsl:if test="@fx and @fy">
557       <xsl:attribute name="GradientOrigin">
558         <xsl:choose>
559           <xsl:when test="contains(@fx, '%') and contains(@fy, '%')">
560             <xsl:value-of select="concat(number(substring-before(@fx, '%')) div 100, ',', number(substring-before(@fy, '%')) div 100)" />
561           </xsl:when>
562           <xsl:otherwise>
563             <xsl:value-of select="concat(@fx, ',', @fy)" />
564           </xsl:otherwise>
565         </xsl:choose>
566       </xsl:attribute>
567     </xsl:if>
568     <xsl:if test="@r">
569       <xsl:choose>
570         <xsl:when test="contains(@r, '%')">
571           <xsl:attribute name="RadiusX">
572             <xsl:value-of select="number(substring-before(@r, '%')) div 100" />
573           </xsl:attribute>
574           <xsl:attribute name="RadiusY">
575             <xsl:value-of select="number(substring-before(@r, '%')) div 100" />
576           </xsl:attribute>
577         </xsl:when>
578         <xsl:otherwise>
579           <xsl:attribute name="RadiusX">
580             <xsl:value-of select="@r" />
581           </xsl:attribute>
582           <xsl:attribute name="RadiusY">
583             <xsl:value-of select="@r" />
584           </xsl:attribute>
585         </xsl:otherwise>
586       </xsl:choose>
587     </xsl:if>
588     <RadialGradientBrush.GradientStops>
589       <GradientStopCollection>
590         <xsl:choose>
591           <xsl:when test="@xlink:href">
592             <xsl:variable name="reference_id" select="@xlink:href" />
593             <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />
594           </xsl:when>
595           <xsl:otherwise>
596             <xsl:apply-templates mode="forward" />
597           </xsl:otherwise>
598         </xsl:choose>
599       </GradientStopCollection>
600     </RadialGradientBrush.GradientStops>
601     <xsl:if test="@gradientTransform">
602       <RadialGradientBrush.Transform>
603         <xsl:apply-templates mode="transform" select="." />
604       </RadialGradientBrush.Transform>
605     </xsl:if>
606   </RadialGradientBrush>
607 </xsl:template>
609 <!--
610   // Gradient stop //
611 -->
612 <xsl:template mode="forward" match="*[name(.) = 'stop']">
613   <GradientStop>
614     <!--xsl:apply-templates mode="stop_opacity" select="." /-->
615     <xsl:apply-templates mode="stop_color" select="." />
616     <xsl:apply-templates mode="offset" select="." />
617     <xsl:apply-templates mode="forward" />
618   </GradientStop>
619 </xsl:template>
621 <!-- 
622   // Clipping //
623 -->
624 <xsl:template mode="clip" match="*">
625   <xsl:choose>
626     <xsl:when test="@clip-path and defs/clipPath/path/@d">
627       <xsl:attribute name="Clip">
628         <xsl:value-of select="defs/clipPath/path/@d" />
629       </xsl:attribute>
630     </xsl:when>
631     <xsl:when test="@clip-path and starts-with(@clip-path, 'url(#')">
632       <xsl:attribute name="Clip">
633         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@clip-path, 'url(#'), ')'), '}')" />
634       </xsl:attribute>
635     </xsl:when>
636     <xsl:when test="@style and contains(@style, 'clip-path:url(#')">
637       <xsl:attribute name="Clip">
638         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" />
639       </xsl:attribute>
640     </xsl:when>
641     <xsl:when test="clipPath">
642       <xsl:apply-templates mode="forward" />
643     </xsl:when>
644   </xsl:choose>
645 </xsl:template>
647 <!--
648 // Misc templates //
650   * Id converter
651   * Decimal to hexadecimal converter
652   * Unit to pixel converter
653   * Object description
654   * Title and description
655   * Switch
656   * Symbols
657   * Use
658   * RDF and foreign objects
659   * Misc ignored stuff (markers, patterns, styles)
660   * Unknows tags
661 -->
663 <!--
664   // Id converter //
665   Removes "-" from the original id
666 -->
667 <xsl:template mode="id" match="*">
668 <xsl:if test="@id">
669   <xsl:attribute name="Name"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>
670   <!--
671     <xsl:attribute name="x:Key"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>
672   -->
673 </xsl:if>
674 </xsl:template>
676 <!--
677   // Decimal to hexadecimal converter //
678 -->
679 <xsl:template name="to_hex">
680   <xsl:param name="convert" />
681   <xsl:value-of select="concat(substring('0123456789ABCDEF', 1 + floor(round($convert) div 16), 1), substring('0123456789ABCDEF', 1 + round($convert) mod 16, 1))" />
682 </xsl:template>
684 <!-- 
685   // Unit to pixel converter //
686   Values with units (except %) are converted to pixels and rounded.
687   Unknown units are kept.
688   em, ex and % not implemented
689 -->
690 <xsl:template name="convert_unit">
691   <xsl:param name="convert_value" />
692   <xsl:choose>
693     <xsl:when test="contains($convert_value, 'px')">
694       <xsl:value-of select="round(translate($convert_value, 'px', ''))" />
695     </xsl:when>
696     <xsl:when test="contains($convert_value, 'pt')">
697       <xsl:value-of select="round(translate($convert_value, 'pt', '') * 1.25)" />
698     </xsl:when>
699     <xsl:when test="contains($convert_value, 'pc')">
700       <xsl:value-of select="round(translate($convert_value, 'pc', '') * 15)" />
701     </xsl:when>
702     <xsl:when test="contains($convert_value, 'mm')">
703       <xsl:value-of select="round(translate($convert_value, 'mm', '') * 3.543307)" />
704     </xsl:when>
705     <xsl:when test="contains($convert_value, 'cm')">
706       <xsl:value-of select="round(translate($convert_value, 'cm', '') * 35.43307)" />
707     </xsl:when>
708     <xsl:when test="contains($convert_value, 'in')">
709       <xsl:value-of select="round(translate($convert_value, 'in', '') * 90)" />
710     </xsl:when>
711     <xsl:when test="contains($convert_value, 'ft')">
712       <xsl:value-of select="round(translate($convert_value, 'ft', '') * 1080)" />
713     </xsl:when>
714     <xsl:when test="not(string(number($convert_value))='NaN')">
715       <xsl:value-of select="round($convert_value)" />
716     </xsl:when>
717     <xsl:otherwise>
718       <xsl:value-of select="$convert_value" />
719     </xsl:otherwise>
720   </xsl:choose>
721 </xsl:template>
723 <!-- 
724   // Object description //
725 -->
726 <xsl:template mode="desc" match="*">
727   <xsl:if test="*[name(.) = 'desc']/text()">
728     <xsl:attribute name="Tag">
729       <xsl:value-of select="*[name(.) = 'desc']/text()" />
730     </xsl:attribute>
731   </xsl:if>
732 </xsl:template>
734 <!-- 
735   // Title and description //
736   Title is ignored and desc is converted to Tag in the mode="desc" template
737 -->
738 <xsl:template mode="forward" match="*[name(.) = 'title' or name(.) = 'desc']">
740 </xsl:template>
742 <!--
743   // Switch //
744 -->
745 <xsl:template mode="forward" match="*[name(.) = 'switch']">
746   <xsl:apply-templates mode="forward" />
747 </xsl:template>
749 <!--
750   // Symbols //
751 -->
752 <xsl:template mode="forward" match="*[name(.) = 'symbol']">
753   <Style>
754     <xsl:if test="@id">
755       <xsl:attribute name="x:Key">
756         <xsl:value-of select="@id" />
757       </xsl:attribute>
758     </xsl:if>
759     <Canvas>
760       <xsl:apply-templates mode="forward" />
761     </Canvas>
762   </Style>
763 </xsl:template>
765 <!--
766   // Use //
767   (since it is not supported by Inkscape, not implemented yet)
768 -->
769 <xsl:template mode="forward" match="*[name(.) = 'use']">
770   <Canvas>
771     <xsl:if test="@xlink:href">
772       <xsl:attribute name="Style">
773         <xsl:value-of select="@xlink:href" />
774       </xsl:attribute>
775     </xsl:if>
776     <!--xsl:apply-templates mode="transform" select="." /-->
777     <xsl:apply-templates mode="forward" />
778   </Canvas>
779 </xsl:template>
781 <!--
782   // RDF and foreign objects //
783 -->
784 <xsl:template mode="forward" match="rdf:RDF | *[name(.) = 'foreignObject']">
786 </xsl:template>
788 <!--
789   // Misc ignored stuff (markers, patterns, styles) //
790 -->
791 <xsl:template mode="forward" match="*[name(.) = 'marker' or name(.) = 'pattern' or name(.) = 'style']">
793 </xsl:template>
795 <!-- 
796   // Unknown tags //
797   With generic and mode="forward" templates
798 -->
799 <xsl:template match="*">
800   <xsl:comment>
801     <xsl:value-of select="concat('Unknown tag: ', name(.))" />
802   </xsl:comment>
803 </xsl:template>
805 <xsl:template mode="forward" match="*">
806   <xsl:comment>
807     <xsl:value-of select="concat('Unknown tag: ', name(.))" />
808   </xsl:comment>
809 </xsl:template>
811 <!--
812 // Colors and patterns //
814 * Generic color template
815 * Fill
816 * Fill opacity
817 * Fill rule
818 * Generic fill template
819 * Stroke
820 * Stroke opacity
821 * Generic stroke template
822 * Stroke width
823 * Stroke mitterlimit
824 * Stroke dasharray
825 * Stroke dashoffset
826 * Linejoin SVG to XAML converter
827 * Stroke linejoin
828 * Linecap SVG to XAML converter
829 * Stroke linecap
830 * Gradient stop
831 * Gradient stop opacity
832 * Gradient stop offset
833 -->
835 <!--
836   // Generic color template //
837 -->
838 <xsl:template name="template_color">
839   <xsl:param name="colorspec" />
840   <xsl:param name="opacityspec" />
841   <xsl:choose>
842     <xsl:when test="starts-with($colorspec, 'rgb(') and not(contains($colorspec , '%'))">
843       <xsl:value-of select="'#'" />
844       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1">
845         <xsl:call-template name="to_hex">
846           <xsl:with-param name="convert">
847             <xsl:value-of select="round(number($opacityspec) * 255)" />
848           </xsl:with-param>
849         </xsl:call-template>
850       </xsl:if>
851       <xsl:call-template name="to_hex">
852         <xsl:with-param name="convert">
853           <xsl:value-of select="substring-before(substring-after($colorspec, 'rgb('), ',')" />
854         </xsl:with-param>
855       </xsl:call-template>
856       <xsl:call-template name="to_hex">
857         <xsl:with-param name="convert">
858           <xsl:value-of select="substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), ',')" />
859         </xsl:with-param>
860       </xsl:call-template>
861       <xsl:call-template name="to_hex">
862         <xsl:with-param name="convert">
863           <xsl:value-of select="substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), ')')" />
864         </xsl:with-param>
865       </xsl:call-template>
866     </xsl:when>
867     <xsl:when test="starts-with($colorspec, 'rgb(') and contains($colorspec , '%')">
868       <xsl:value-of select="'#'" />
869       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1">
870         <xsl:call-template name="to_hex">
871           <xsl:with-param name="convert">
872             <xsl:value-of select="round(number($opacityspec) * 255)" />
873           </xsl:with-param>
874         </xsl:call-template>
875       </xsl:if>
876       <xsl:call-template name="to_hex">
877         <xsl:with-param name="convert">
878           <xsl:value-of select="number(substring-before(substring-after($colorspec, 'rgb('), '%,')) * 255 div 100" />
879         </xsl:with-param>
880       </xsl:call-template>
881       <xsl:call-template name="to_hex">
882         <xsl:with-param name="convert">
883           <xsl:value-of select="number(substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), '%,')) * 255 div 100" />
884         </xsl:with-param>
885       </xsl:call-template>
886       <xsl:call-template name="to_hex">
887         <xsl:with-param name="convert">
888           <xsl:value-of select="number(substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), '%)')) * 255 div 100" />
889         </xsl:with-param>
890       </xsl:call-template>
891     </xsl:when>
892     <xsl:when test="starts-with($colorspec, '#')">
893       <xsl:value-of select="'#'" />
894       <xsl:if test="$opacityspec != ''">
895         <xsl:call-template name="to_hex">
896           <xsl:with-param name="convert">
897             <xsl:value-of select="round(number($opacityspec) * 255)" />
898           </xsl:with-param>
899         </xsl:call-template>
900       </xsl:if>
901       <xsl:choose>
902         <xsl:when test="string-length(substring-after($colorspec, '#')) = 3">
903           <xsl:variable name="colorspec3">
904             <xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" />
905           </xsl:variable>
906           <xsl:value-of select="concat(substring($colorspec3, 1, 1), substring($colorspec3, 1, 1))" />
907           <xsl:value-of select="concat(substring($colorspec3, 2, 1), substring($colorspec3, 2, 1))" />
908           <xsl:value-of select="concat(substring($colorspec3, 3, 1), substring($colorspec3, 3, 1))" />
909         </xsl:when>
910         <xsl:otherwise>
911           <xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" />
912         </xsl:otherwise>
913       </xsl:choose>
914     </xsl:when>
915     <xsl:otherwise>
916       <xsl:variable name="named_color_hex" select="document('colors.xml')/colors/color[@name = translate($colorspec, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]/@hex" />
917       <xsl:choose>
918         <xsl:when test="$named_color_hex and $named_color_hex != ''">
919           <xsl:value-of select="'#'" />
920           <xsl:if test="$opacityspec != '' and number($opacityspec) != 1">
921             <xsl:call-template name="to_hex">
922               <xsl:with-param name="convert">
923                 <xsl:value-of select="number($opacityspec) * 255" />
924               </xsl:with-param>
925             </xsl:call-template>
926           </xsl:if>
927           <xsl:value-of select="substring-after($named_color_hex, '#')" />
928         </xsl:when>
929         <xsl:otherwise>
930           <xsl:value-of select="$colorspec" />
931         </xsl:otherwise>
932       </xsl:choose>
933     </xsl:otherwise>
934   </xsl:choose>
935 </xsl:template>
937 <!--
938   // Fill //
939 -->
940 <xsl:template mode="fill" match="*">
941   <xsl:variable name="value">
942     <xsl:choose>
943       <xsl:when test="@fill and starts-with(@fill, 'url(#')">
944         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@fill, 'url(#'), ')'), '}')" />
945       </xsl:when>
946       <xsl:when test="@fill">
947         <xsl:value-of select="@fill" />
948       </xsl:when>
949       <xsl:when test="@style and contains(@style, 'fill:') and starts-with(substring-after(@style, 'fill:'), 'url(#')">
950         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" />
951       </xsl:when>
952       <xsl:when test="@style and contains(@style, 'fill:')">
953         <xsl:variable name="Fill" select="substring-after(@style, 'fill:')" />
954         <xsl:choose>
955           <xsl:when test="contains($Fill, ';')">
956             <xsl:value-of select="substring-before($Fill, ';')" />
957           </xsl:when>
958           <xsl:otherwise>
959             <xsl:value-of select="$Fill" />
960           </xsl:otherwise>
961         </xsl:choose>
962       </xsl:when>
963       <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
964         <xsl:apply-templates mode="fill" select="parent::*"/>
965       </xsl:when>
966     </xsl:choose>
967   </xsl:variable>
968   <xsl:if test="$value">
969     <!-- Removes unwanted characters in the color link (TODO: export to a specific template)-->
970     <xsl:value-of select="normalize-space(translate($value, '&quot;', ''))" />
971   </xsl:if>
972 </xsl:template>
974 <!--
975   // Fill opacity //
976 -->
977 <xsl:template mode="fill_opacity" match="*">
978   <xsl:variable name="value">
979   <xsl:choose>
980     <xsl:when test="@fill-opacity">
981       <xsl:value-of select="@fill-opacity" />
982     </xsl:when>
983     <xsl:when test="@style and contains(@style, 'fill-opacity:')">
984       <xsl:variable name="Opacity" select="substring-after(@style, 'fill-opacity:')" />
985       <xsl:choose>
986         <xsl:when test="contains($Opacity, ';')">
987           <xsl:value-of select="substring-before($Opacity, ';')" />
988         </xsl:when>
989         <xsl:otherwise>
990           <xsl:value-of select="$Opacity" />
991         </xsl:otherwise>
992       </xsl:choose>
993     </xsl:when>
994     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
995       <xsl:apply-templates mode="fill_opacity" select="parent::*" />
996     </xsl:when>
997     <xsl:otherwise>1</xsl:otherwise>
998   </xsl:choose>
999   </xsl:variable>
1000   <xsl:choose>
1001     <xsl:when test="$value &lt; 0">0</xsl:when>
1002     <xsl:when test="$value &gt; 1">1</xsl:when>
1003     <xsl:otherwise>
1004       <xsl:value-of select="$value" />
1005     </xsl:otherwise>
1006   </xsl:choose>
1007 </xsl:template>
1009 <!--
1010   // Fill rule //
1011 -->
1012 <xsl:template mode="fill_rule" match="*">
1013   <xsl:choose>
1014     <xsl:when test="@fill-rule and (@fill-rule = 'nonzero' or @fill-rule = 'evenodd')">
1015       <xsl:attribute name="FillRule">
1016         <xsl:value-of select="@fill-rule" />
1017       </xsl:attribute>
1018     </xsl:when>
1019     <xsl:when test="@style and contains(@style, 'fill-rule:')">
1020       <xsl:variable name="FillRule" select="normalize-space(substring-after(@style, 'fill-rule:'))" />
1021       <xsl:choose>
1022         <xsl:when test="contains($FillRule, ';')">
1023           <xsl:if test="substring-before($FillRule, ';') = 'nonzero' or substring-before($FillRule, ';') = 'evenodd'">
1024             <xsl:attribute name="FillRule">
1025               <xsl:value-of select="substring-before($FillRule, ';')" />
1026             </xsl:attribute>
1027           </xsl:if>
1028         </xsl:when>
1029         <xsl:when test="$FillRule = 'nonzero' or $FillRule = 'evenodd'">
1030           <xsl:attribute name="FillRule">
1031             <xsl:value-of select="$FillRule" />
1032           </xsl:attribute>
1033         </xsl:when>
1034       </xsl:choose>
1035     </xsl:when>
1036     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1037       <xsl:apply-templates mode="fill_rule" select="parent::*"/>
1038     </xsl:when>
1039     <xsl:otherwise>
1040       <xsl:attribute name="FillRule">NonZero</xsl:attribute>
1041     </xsl:otherwise>
1042   </xsl:choose>
1043 </xsl:template>
1045 <!--
1046   // Generic fill template //
1047 -->
1048 <xsl:template mode="template_fill" match="*">
1049   <xsl:variable name="fill"><xsl:apply-templates mode="fill" select="." /></xsl:variable>
1050   <xsl:variable name="fill_opacity"><xsl:apply-templates mode="fill_opacity" select="." /></xsl:variable>
1051   <xsl:if test="not($fill = 'none')">
1052     <xsl:attribute name="Fill">
1053       <xsl:choose>
1054         <xsl:when test="$fill != ''">
1055           <xsl:call-template name="template_color">
1056             <xsl:with-param name="colorspec">
1057               <xsl:if test="$fill != 'none'">
1058                 <xsl:value-of select="$fill" />
1059               </xsl:if>
1060             </xsl:with-param>
1061             <xsl:with-param name="opacityspec">
1062               <xsl:value-of select="$fill_opacity" />
1063             </xsl:with-param>
1064           </xsl:call-template>
1065         </xsl:when>
1066         <xsl:otherwise>#000000</xsl:otherwise>
1067       </xsl:choose>
1068     </xsl:attribute>
1069   </xsl:if>
1070 </xsl:template>
1072 <!--
1073   // Stroke //
1074 -->
1075 <xsl:template mode="stroke" match="*">
1076   <xsl:choose>
1077     <xsl:when test="@stroke and starts-with(@stroke, 'url(#')">
1078       <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@stroke, 'url(#'), ')'), '}')" />
1079     </xsl:when>
1080     <xsl:when test="@stroke and @stroke != 'none'">
1081       <xsl:value-of select="@stroke" />
1082     </xsl:when>
1083     <xsl:when test="@style and contains(@style, 'stroke:') and starts-with(substring-after(@style, 'stroke:'), 'url(#')">
1084       <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" />
1085     </xsl:when>
1086     <xsl:when test="@style and contains(@style, 'stroke:')">
1087       <xsl:variable name="Stroke" select="substring-after(@style, 'stroke:')" />
1088       <xsl:choose>
1089         <xsl:when test="contains($Stroke, ';')">
1090           <xsl:if test="substring-before($Stroke, ';') != 'none'">
1091             <xsl:value-of select="substring-before($Stroke, ';')" />
1092           </xsl:if>
1093         </xsl:when>
1094         <xsl:when test="$Stroke != 'none'">
1095           <xsl:value-of select="$Stroke" />
1096         </xsl:when>
1097       </xsl:choose>
1098     </xsl:when>
1099     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1100       <xsl:apply-templates mode="stroke" select="parent::*"/>
1101     </xsl:when>
1102   </xsl:choose>
1103 </xsl:template>
1105 <!--
1106   // Stroke opacity //
1107 -->
1108 <xsl:template mode="stroke_opacity" match="*">
1109   <xsl:variable name="value">
1110   <xsl:choose>
1111     <xsl:when test="@stroke-opacity">
1112       <xsl:value-of select="@stroke-opacity" />
1113     </xsl:when>
1114     <xsl:when test="@style and contains(@style, 'stroke-opacity:')">
1115       <xsl:variable name="Opacity" select="substring-after(@style, 'stroke-opacity:')" />
1116       <xsl:choose>
1117         <xsl:when test="contains($Opacity, ';')">
1118           <xsl:value-of select="substring-before($Opacity, ';')" />
1119         </xsl:when>
1120         <xsl:otherwise>
1121           <xsl:value-of select="$Opacity" />
1122         </xsl:otherwise>
1123       </xsl:choose>
1124     </xsl:when>
1125     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1126       <xsl:apply-templates mode="stroke_opacity" select="parent::*" />
1127     </xsl:when>
1128     <xsl:otherwise>1</xsl:otherwise>
1129   </xsl:choose>
1130   </xsl:variable>
1131   <xsl:choose>
1132     <xsl:when test="$value &lt; 0">0</xsl:when>
1133     <xsl:when test="$value &gt; 1">1</xsl:when>
1134     <xsl:otherwise>
1135       <xsl:value-of select="$value" />
1136     </xsl:otherwise>
1137   </xsl:choose>
1138 </xsl:template>
1140 <!-- 
1141   // Generic stroke template //
1142  -->
1143 <xsl:template mode="template_stroke" match="*">
1144   <xsl:variable name="stroke">
1145     <xsl:apply-templates mode="stroke" select="." />
1146   </xsl:variable>
1147   <xsl:variable name="stroke_opacity">
1148     <xsl:apply-templates mode="stroke_opacity" select="." />
1149   </xsl:variable>
1150   <xsl:variable name="stroke_width">
1151     <xsl:apply-templates mode="stroke_width" select="." />
1152   </xsl:variable>
1153   
1154   <xsl:if test="$stroke_width != ''">
1155     <xsl:attribute name="StrokeThickness">
1156       <xsl:value-of select="$stroke_width" />
1157     </xsl:attribute>
1158   </xsl:if>
1159   <xsl:if test="$stroke != ''">
1160     <xsl:attribute name="Stroke">
1161       <xsl:call-template name="template_color">
1162         <xsl:with-param name="colorspec">
1163           <xsl:value-of select="$stroke" />
1164         </xsl:with-param>
1165         <xsl:with-param name="opacityspec">
1166           <xsl:value-of select="$stroke_opacity" />
1167         </xsl:with-param>
1168       </xsl:call-template>
1169     </xsl:attribute>
1170   </xsl:if>
1171 </xsl:template>
1173 <!--
1174   // Stroke width //
1175 -->
1176 <xsl:template mode="stroke_width" match="*">
1177   <xsl:choose>
1178     <xsl:when test="@stroke-width">
1179       <xsl:call-template name="convert_unit">
1180         <xsl:with-param name="convert_value">
1181           <xsl:value-of select="@stroke-width" />
1182         </xsl:with-param>
1183       </xsl:call-template> 
1184     </xsl:when>
1185     <xsl:when test="@style and contains(@style, 'stroke-width:')">
1186       <xsl:call-template name="convert_unit">
1187         <xsl:with-param name="convert_value">
1188         <xsl:choose>
1189           <xsl:when test="contains(substring-after(@style, 'stroke-width:'), ';')">
1190             <xsl:value-of select="substring-before(substring-after(@style, 'stroke-width:'), ';')" />
1191           </xsl:when>
1192           <xsl:otherwise>
1193             <xsl:value-of select="substring-after(@style, 'stroke-width:')" />
1194           </xsl:otherwise>
1195         </xsl:choose>
1196         </xsl:with-param>
1197       </xsl:call-template> 
1198     </xsl:when>
1199     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1200       <xsl:apply-templates mode="stroke_width" select="parent::*"/>
1201     </xsl:when>
1202   </xsl:choose>
1203 </xsl:template>
1205 <!--
1206   // Stroke miterlimit //
1207 -->
1208 <xsl:template mode="stroke_miterlimit" match="*">
1209   <xsl:choose>
1210     <xsl:when test="@stroke-miterlimit">
1211       <xsl:attribute name="StrokeMiterLimit">
1212         <xsl:value-of select="@stroke-miterlimit" />
1213       </xsl:attribute>
1214     </xsl:when>
1215     <xsl:when test="@style and contains(@style, 'stroke-miterlimit:')">
1216       <xsl:variable name="StrokeMiterLimit" select="substring-after(@style, 'stroke-miterlimit:')" />
1217       <xsl:attribute name="StrokeMiterLimit">
1218         <xsl:choose>
1219           <xsl:when test="contains($StrokeMiterLimit, ';')">
1220             <xsl:value-of select="substring-before($StrokeMiterLimit, ';')" />
1221           </xsl:when>
1222           <xsl:otherwise>
1223             <xsl:value-of select="$StrokeMiterLimit" />
1224           </xsl:otherwise>
1225         </xsl:choose>
1226       </xsl:attribute>
1227     </xsl:when>
1228     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1229       <xsl:apply-templates mode="stroke_miterlimit" select="parent::*"/>
1230     </xsl:when>
1231   </xsl:choose>
1232 </xsl:template>
1234 <!-- 
1235   // Stroke dasharray //
1236 -->
1237 <xsl:template mode="stroke_dasharray" match="*">
1238   <!-- stroke-dasharray="10,30,20,30" becomes StrokeDashArray="1 3 2 3" ?? -->
1239   <xsl:choose>
1240     <xsl:when test="@stroke-dasharray and @stroke-dasharray != 'none'">
1241       <xsl:attribute name="StrokeDashArray">
1242         <xsl:value-of select="@stroke-dasharray" />
1243       </xsl:attribute>
1244     </xsl:when>
1245     <xsl:when test="@style and contains(@style, 'stroke-dasharray:')">
1246       <xsl:variable name="StrokeDashArray" select="substring-after(@style, 'stroke-dasharray:')" />
1247       <xsl:choose>
1248         <xsl:when test="contains($StrokeDashArray, ';')">
1249           <xsl:if test="substring-before($StrokeDashArray, ';') != 'none'">
1250             <xsl:attribute name="StrokeDashArray">
1251               <xsl:value-of select="substring-before($StrokeDashArray, ';')" />
1252             </xsl:attribute>
1253           </xsl:if>
1254         </xsl:when>
1255         <xsl:when test="$StrokeDashArray != 'none'">
1256           <xsl:attribute name="StrokeDashArray">
1257             <xsl:value-of select="$StrokeDashArray" />
1258           </xsl:attribute>
1259         </xsl:when>
1260       </xsl:choose>
1261     </xsl:when>
1262     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1263       <xsl:apply-templates mode="stroke_dasharray" select="parent::*"/>
1264     </xsl:when>
1265   </xsl:choose>
1266 </xsl:template>
1268 <!-- 
1269   // Stroke dashoffset //
1270 -->
1271 <xsl:template mode="stroke_dashoffset" match="*">
1272   <xsl:choose>
1273     <xsl:when test="@stroke-dashoffset">
1274       <xsl:attribute name="StrokeDashOffset">
1275         <xsl:value-of select="@stroke-dashoffset" />
1276       </xsl:attribute>
1277     </xsl:when>
1278     <xsl:when test="@style and contains(@style, 'stroke-dashoffset:')">
1279       <xsl:variable name="StrokeDashOffset" select="substring-after(@style, 'stroke-dashoffset:')" />
1280       <xsl:attribute name="StrokeDashOffset">
1281         <xsl:choose>
1282           <xsl:when test="contains($StrokeDashOffset, ';')">
1283             <xsl:value-of select="substring-before($StrokeDashOffset, ';')" />
1284           </xsl:when>
1285           <xsl:otherwise>
1286             <xsl:value-of select="$StrokeDashOffset" />
1287           </xsl:otherwise>
1288         </xsl:choose>
1289       </xsl:attribute>
1290     </xsl:when>
1291     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1292       <xsl:apply-templates mode="stroke_dashoffset" select="parent::*"/>
1293     </xsl:when>
1294   </xsl:choose>
1295 </xsl:template>
1297 <!-- 
1298   // Linejoin SVG to XAML converter //
1299 -->
1300 <xsl:template name="linejoin_svg_to_xaml">
1301   <xsl:param name="linejoin" />
1302   <xsl:choose>
1303     <xsl:when test="$linejoin = 'bevel'">Bevel</xsl:when>
1304     <xsl:when test="$linejoin = 'round'">Round</xsl:when>
1305     <xsl:otherwise>Miter</xsl:otherwise>
1306   </xsl:choose>
1307 </xsl:template>
1309 <!-- 
1310   // Stroke linejoin //
1311 -->
1312 <xsl:template mode="stroke_linejoin" match="*">
1313   <xsl:choose>
1314     <xsl:when test="@stroke-miterlimit">
1315       <xsl:attribute name="StrokeLineJoin">
1316         <xsl:call-template name="linejoin_svg_to_xaml">
1317           <xsl:with-param name="linejoin">
1318             <xsl:value-of select="@stroke-linejoin" />
1319           </xsl:with-param>
1320         </xsl:call-template>
1321       </xsl:attribute>
1322     </xsl:when>
1323     <xsl:when test="@style and contains(@style, 'stroke-linejoin:')">
1324       <xsl:variable name="StrokeLineJoin" select="substring-after(@style, 'stroke-linejoin:')" />
1325       <xsl:attribute name="StrokeLineJoin">
1326         <xsl:choose>
1327           <xsl:when test="contains($StrokeLineJoin, ';')">
1328             <xsl:call-template name="linejoin_svg_to_xaml">
1329               <xsl:with-param name="linejoin">
1330                 <xsl:value-of select="substring-before($StrokeLineJoin, ';')" />
1331               </xsl:with-param>
1332             </xsl:call-template>
1333           </xsl:when>
1334           <xsl:otherwise>
1335             <xsl:call-template name="linejoin_svg_to_xaml">
1336               <xsl:with-param name="linejoin">
1337                 <xsl:value-of select="$StrokeLineJoin" />
1338               </xsl:with-param>
1339             </xsl:call-template>
1340           </xsl:otherwise>
1341         </xsl:choose>
1342       </xsl:attribute>
1343     </xsl:when>
1344     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1345       <xsl:apply-templates mode="stroke_linejoin" select="parent::*"/>
1346     </xsl:when>
1347   </xsl:choose>
1348 </xsl:template>
1350 <!-- 
1351   // Linecap SVG to XAML converter //
1352 -->
1353 <xsl:template name="linecap_svg_to_xaml">
1354   <xsl:param name="linecap" />
1355   <xsl:choose>
1356     <xsl:when test="$linecap = 'round'">Round</xsl:when>
1357     <xsl:when test="$linecap = 'square'">Square</xsl:when>
1358     <xsl:otherwise>Flat</xsl:otherwise>
1359   </xsl:choose>
1360 </xsl:template>
1362 <!--
1363   // Stroke linecap //
1364 -->
1365 <xsl:template mode="stroke_linecap" match="*">
1366   <xsl:choose>
1367     <xsl:when test="@stroke-linecap">
1368       <xsl:attribute name="StrokeStartLineCap">
1369         <xsl:call-template name="linecap_svg_to_xaml">
1370           <xsl:with-param name="linecap">
1371             <xsl:value-of select="@stroke-linecap" />
1372           </xsl:with-param>
1373         </xsl:call-template>
1374       </xsl:attribute>
1375       <xsl:attribute name="StrokeEndLineCap">
1376         <xsl:call-template name="linecap_svg_to_xaml">
1377           <xsl:with-param name="linecap">
1378             <xsl:value-of select="@stroke-linecap" />
1379           </xsl:with-param>
1380         </xsl:call-template>
1381       </xsl:attribute>
1382     </xsl:when>
1383     <xsl:when test="@style and contains(@style, 'stroke-linecap:')">
1384       <xsl:variable name="StrokeStartLineCap" select="substring-after(@style, 'stroke-linecap:')" />
1385       <xsl:variable name="StrokeEndLineCap" select="substring-after(@style, 'stroke-linecap:')" />
1386       <xsl:attribute name="StrokeStartLineCap">
1387         <xsl:choose>
1388           <xsl:when test="contains($StrokeStartLineCap, ';')">
1389             <xsl:call-template name="linecap_svg_to_xaml">
1390               <xsl:with-param name="linecap">
1391                 <xsl:value-of select="substring-before($StrokeStartLineCap, ';')" />
1392               </xsl:with-param>
1393             </xsl:call-template>
1394           </xsl:when>
1395           <xsl:otherwise>
1396             <xsl:call-template name="linecap_svg_to_xaml">
1397               <xsl:with-param name="linecap">
1398                 <xsl:value-of select="$StrokeStartLineCap" />
1399               </xsl:with-param>
1400             </xsl:call-template>
1401           </xsl:otherwise>
1402         </xsl:choose>
1403       </xsl:attribute>
1404       <xsl:attribute name="StrokeEndLineCap">
1405         <xsl:choose>
1406           <xsl:when test="contains($StrokeEndLineCap, ';')">
1407             <xsl:call-template name="linecap_svg_to_xaml">
1408               <xsl:with-param name="linecap">
1409                 <xsl:value-of select="substring-before($StrokeEndLineCap, ';')" />
1410               </xsl:with-param>
1411             </xsl:call-template>
1412           </xsl:when>
1413           <xsl:otherwise>
1414             <xsl:call-template name="linecap_svg_to_xaml">
1415               <xsl:with-param name="linecap">
1416                 <xsl:value-of select="$StrokeEndLineCap" />
1417               </xsl:with-param>
1418             </xsl:call-template>
1419           </xsl:otherwise>
1420         </xsl:choose>
1421       </xsl:attribute>
1422     </xsl:when>
1423     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1424       <xsl:apply-templates mode="stroke_linecap" select="parent::*"/>
1425     </xsl:when>
1426   </xsl:choose>
1427 </xsl:template>
1429 <!-- 
1430   // Gradient stops //
1431 -->
1432 <xsl:template mode="stop_color" match="*">
1433   <xsl:variable name="Opacity">
1434     <xsl:choose>
1435       <xsl:when test="@stop-opacity">
1436         <xsl:value-of select="@stop-opacity" />
1437       </xsl:when>
1438       <xsl:when test="@style and contains(@style, 'stop-opacity:')">
1439         <xsl:variable name="temp_opacity" select="substring-after(@style, 'stop-opacity:')" />
1440         <xsl:choose>
1441           <xsl:when test="contains($temp_opacity, ';')">
1442             <xsl:value-of select="substring-before($temp_opacity, ';')" />
1443           </xsl:when>
1444           <xsl:otherwise>
1445             <xsl:value-of select="$temp_opacity" />
1446           </xsl:otherwise>
1447         </xsl:choose>
1448       </xsl:when>
1449       <xsl:otherwise>
1450         <xsl:value-of select="''" />
1451       </xsl:otherwise>
1452     </xsl:choose>
1453   </xsl:variable>
1454   <xsl:variable name="hex_opacity">
1455     <xsl:choose>
1456       <xsl:when test="$Opacity != ''">
1457         <xsl:call-template name="to_hex">
1458           <xsl:with-param name="convert">
1459             <xsl:value-of select="number($Opacity) * 255" />
1460           </xsl:with-param>
1461         </xsl:call-template>
1462       </xsl:when>
1463       <xsl:otherwise>
1464         <xsl:value-of select="$Opacity" />
1465       </xsl:otherwise>
1466     </xsl:choose>
1467   </xsl:variable>
1468   <xsl:variable name="stopcolor">
1469     <xsl:choose>
1470       <xsl:when test="@stop-color">
1471         <xsl:call-template name="template_color">
1472           <xsl:with-param name="colorspec">
1473             <xsl:value-of select="@stop-color" />
1474           </xsl:with-param>
1475         </xsl:call-template>
1476       </xsl:when>
1477       <xsl:when test="@style and contains(@style, 'stop-color:')">
1478         <xsl:variable name="Color" select="substring-after(@style, 'stop-color:')" />
1479         <xsl:choose>
1480           <xsl:when test="contains($Color, ';')">
1481             <xsl:call-template name="template_color">
1482               <xsl:with-param name="colorspec">
1483                 <xsl:value-of select="substring-before($Color, ';')" />
1484               </xsl:with-param>
1485             </xsl:call-template>
1486           </xsl:when>
1487           <xsl:otherwise>
1488             <xsl:call-template name="template_color">
1489               <xsl:with-param name="colorspec">
1490                 <xsl:value-of select="$Color" />
1491               </xsl:with-param>
1492             </xsl:call-template>
1493           </xsl:otherwise>
1494         </xsl:choose>
1495       </xsl:when>
1496       <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1497         <xsl:apply-templates mode="stop_color" select="parent::*"/>
1498       </xsl:when>
1499       <xsl:otherwise>#000</xsl:otherwise>
1500     </xsl:choose>
1501   </xsl:variable>
1502   <xsl:attribute name="Color">
1503     <xsl:choose>
1504       <xsl:when test="$hex_opacity != '' and starts-with($stopcolor, '#')">
1505         <xsl:value-of select="concat('#', $hex_opacity, substring-after($stopcolor, '#'))" />
1506       </xsl:when>
1507       <xsl:otherwise>
1508         <xsl:value-of select="$stopcolor" />
1509       </xsl:otherwise>
1510     </xsl:choose>
1511   </xsl:attribute>
1512 </xsl:template>
1514 <!--
1515   // Gradient stop opacity //
1516 -->
1517 <xsl:template mode="stop_opacity" match="*">
1518   <xsl:choose>
1519     <xsl:when test="@stop-opacity">
1520       <xsl:attribute name="Opacity">
1521         <xsl:value-of select="@stop-opacity" />
1522       </xsl:attribute>
1523     </xsl:when>
1524     <xsl:when test="@style and contains(@style, 'stop-opacity:')">
1525       <xsl:variable name="Opacity" select="substring-after(@style, 'stop-opacity:')" />
1526       <xsl:attribute name="Opacity">
1527         <xsl:choose>
1528           <xsl:when test="contains($Opacity, ';')">
1529             <xsl:value-of select="substring-before($Opacity, ';')" />
1530           </xsl:when>
1531           <xsl:otherwise>
1532             <xsl:value-of select="$Opacity" />
1533           </xsl:otherwise>
1534         </xsl:choose>
1535       </xsl:attribute>
1536     </xsl:when>
1537     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1538       <xsl:apply-templates mode="stop_opacity" select="parent::*"/>
1539     </xsl:when>
1540   </xsl:choose>
1541 </xsl:template>
1543 <!--
1544   // Gradient stop offset //
1545 -->
1546 <xsl:template mode="offset" match="*">
1547   <xsl:choose>
1548     <xsl:when test="@offset">
1549       <xsl:attribute name="Offset">
1550         <xsl:choose>
1551           <xsl:when test="contains(@offset, '%')">
1552             <xsl:value-of select="number(substring-before(@offset, '%')) div 100" />
1553           </xsl:when>
1554           <xsl:otherwise>
1555             <xsl:value-of select="@offset" />
1556           </xsl:otherwise>
1557         </xsl:choose>
1558       </xsl:attribute>
1559     </xsl:when>
1560     <xsl:when test="@style and contains(@style, 'offset:')">
1561       <xsl:variable name="Offset" select="substring-after(@style, 'offset:')" />
1562       <xsl:attribute name="Offset">
1563         <xsl:choose>
1564           <xsl:when test="contains($Offset, '%')">
1565             <xsl:value-of select="number(substring-before($Offset, '%')) div 100" />
1566           </xsl:when>        
1567           <xsl:when test="contains($Offset, ';')">
1568             <xsl:value-of select="substring-before($Offset, ';')" />
1569           </xsl:when>
1570           <xsl:otherwise>
1571             <xsl:value-of select="$Offset" />
1572           </xsl:otherwise>
1573         </xsl:choose>
1574       </xsl:attribute>
1575     </xsl:when>
1576     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1577       <xsl:apply-templates mode="stop_offset" select="parent::*"/>
1578     </xsl:when>
1579   </xsl:choose>
1580 </xsl:template>
1582 <!-- 
1583   // Text specific templates //
1585   * Text tspan
1586   * Text flowPara
1587   * Text flowRegion (text frame)
1588   * Get font size
1589   * Font size
1590   * Font weight
1591   * Font family
1592   * Font style
1593   * Baseline shift
1594   * Line height
1595   * Writing mode
1596   * Text decoration
1597   * Text fill
1598   * Text direction
1599   * Text size
1600   * Text position
1601   * Text object
1602   * FlowRoot object
1603 -->
1605  <!-- 
1606   // Text span //
1607   SVG: tspan, flowSpan, FXG: span
1608   
1609   Not supported in FXG:
1610   * span position
1611 -->
1612 <xsl:template mode="forward" match="*[name(.) = 'tspan'  or name(.) = 'flowSpan']">
1613   <span>
1614     <xsl:if test="../@xml:space='preserve'">
1615       <xsl:attribute name="whiteSpaceCollapse">preserve</xsl:attribute>
1616     </xsl:if>
1617     <xsl:variable name="fill">
1618       <xsl:apply-templates mode="fill" select="." />
1619     </xsl:variable>
1620     <xsl:variable name="fill_opacity">
1621       <xsl:apply-templates mode="fill_opacity" select="." />
1622     </xsl:variable>
1623     <xsl:if test="starts-with($fill, '#') or (not(starts-with($fill, 'url')) and $fill != '' and $fill != 'none')">
1624       <xsl:attribute name="color">
1625         <xsl:call-template name="template_color">
1626           <xsl:with-param name="colorspec">
1627             <xsl:value-of select="$fill" />
1628           </xsl:with-param>
1629         </xsl:call-template>
1630       </xsl:attribute>
1631       <xsl:attribute name="textAlpha">
1632         <xsl:value-of select="$fill_opacity" />
1633       </xsl:attribute>
1634     </xsl:if>
1635     <xsl:apply-templates mode="font_size" select="." />
1636     <xsl:apply-templates mode="font_weight" select="." />
1637     <xsl:apply-templates mode="font_family" select="." />
1638     <xsl:apply-templates mode="font_style" select="." />
1639     <xsl:apply-templates mode="text_fill" select="." />
1640     <xsl:apply-templates mode="text_decoration" select="." />
1641     <xsl:apply-templates mode="line_height" select="." />
1642     <xsl:apply-templates mode="baseline_shift" select="." />
1643     
1644     <xsl:if test="text()">
1645       <xsl:value-of select="text()" />
1646     </xsl:if>
1647   </span>
1648 </xsl:template>
1650  <!-- 
1651   // Text flowPara //
1652   SVG: flowPara, flowDiv FXG: p
1653   
1654   Not supported in FXG:
1655   * paragraph position
1656 -->
1657 <xsl:template mode="forward" match="*[name(.) = 'flowPara' or name(.) = 'flowDiv']">
1658   <p>
1659     <xsl:if test="../@xml:space='preserve'">
1660       <xsl:attribute name="whiteSpaceCollapse">preserve</xsl:attribute>
1661     </xsl:if>
1662     <xsl:variable name="fill">
1663       <xsl:apply-templates mode="fill" select="." />
1664     </xsl:variable>
1665     <xsl:variable name="fill_opacity">
1666       <xsl:apply-templates mode="fill_opacity" select="." />
1667     </xsl:variable>
1668     <xsl:if test="starts-with($fill, '#') or (not(starts-with($fill, 'url')) and $fill != '' and $fill != 'none')">
1669       <xsl:attribute name="color">
1670         <xsl:call-template name="template_color">
1671           <xsl:with-param name="colorspec">
1672             <xsl:value-of select="$fill" />
1673           </xsl:with-param>
1674         </xsl:call-template>
1675       </xsl:attribute>
1676       <xsl:attribute name="textAlpha">
1677         <xsl:value-of select="$fill_opacity" />
1678       </xsl:attribute>
1679     </xsl:if>
1680     <xsl:apply-templates mode="font_size" select="." />
1681     <xsl:apply-templates mode="font_weight" select="." />
1682     <xsl:apply-templates mode="font_family" select="." />
1683     <xsl:apply-templates mode="font_style" select="." />
1684     <xsl:apply-templates mode="text_fill" select="." />
1685     <xsl:apply-templates mode="text_decoration" select="." />
1686     <xsl:apply-templates mode="line_height" select="." />
1687     <xsl:apply-templates mode="baseline_shift" select="." />
1689     <xsl:choose>
1690       <xsl:when test="*[name(.) = 'flowSpan']/text()">
1691         <xsl:apply-templates mode="forward" />
1692       </xsl:when>
1693       <xsl:otherwise>
1694         <xsl:choose>
1695           <xsl:when test="@xml:space='preserve'">
1696             <xsl:copy-of select="translate(text(), '&#x9;&#xA;&#xD;', ' ')" />
1697           </xsl:when>
1698           <xsl:otherwise>
1699             <xsl:copy-of select="normalize-space(translate(text(), '&#x9;&#xA;&#xD;', ' '))" />
1700           </xsl:otherwise>
1701         </xsl:choose>  
1702       </xsl:otherwise>
1703     </xsl:choose>
1704   </p>
1705 </xsl:template>
1708  <!-- 
1709   // Text flowRegion //
1710 -->
1711 <xsl:template mode="flow_region" match="*">
1712   <xsl:apply-templates mode="text_size" select="." />
1713   <xsl:apply-templates mode="text_position" select="." />
1714 </xsl:template>
1716 <!-- 
1717   // Get text font size //
1718 -->
1719 <xsl:template mode="get_font_size" match="*">
1720   <xsl:choose>
1721     <xsl:when test="@font-size">
1722       <xsl:value-of select="@font-size" />
1723     </xsl:when>
1724     <xsl:when test="@style and contains(@style, 'font-size:')">
1725       <xsl:variable name="font_size" select="normalize-space(substring-after(@style, 'font-size:'))" />
1726       <xsl:choose>
1727         <xsl:when test="contains($font_size, ';')">
1728           <xsl:value-of select="substring-before($font_size, ';')" />
1729         </xsl:when>
1730         <xsl:otherwise>
1731           <xsl:value-of select="$font_size" />
1732         </xsl:otherwise>
1733       </xsl:choose>
1734     </xsl:when>
1735     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1736       <xsl:apply-templates mode="get_font_size" select="parent::*"/>
1737     </xsl:when>
1738   </xsl:choose>
1739 </xsl:template>
1740 <!-- 
1741   // Text font size //
1742   SVG: font-size, XAML: FontSize
1743 -->
1744 <xsl:template mode="font_size" match="*">
1745   <xsl:variable name="value">
1746     <xsl:apply-templates mode="get_font_size" select="." />
1747   </xsl:variable>
1748   <xsl:if test="$value != ''">
1749     <xsl:attribute name="FontSize">
1750       <xsl:call-template name="convert_unit">
1751         <xsl:with-param name="convert_value" select="$value" />
1752       </xsl:call-template>
1753     </xsl:attribute>
1754   </xsl:if>
1755   <xsl:attribute name="FontSize">
1756     <xsl:choose>
1757       <xsl:when test="$value != ''">
1758         <xsl:call-template name="convert_unit">
1759           <xsl:with-param name="convert_value" select="$value" />
1760         </xsl:call-template>
1761       </xsl:when>
1762       <xsl:otherwise>12</xsl:otherwise>
1763     </xsl:choose>
1764   </xsl:attribute>
1765 </xsl:template>
1767 <!-- 
1768   // Text font weight //
1769   SVG: font-weight, XAML: FontWeight
1770 -->
1771 <xsl:template mode="font_weight" match="*">
1772   <xsl:variable name="value">
1773     <xsl:if test="@font-weight">
1774       <xsl:value-of select="@font-weight" />
1775     </xsl:if>
1776     <xsl:if test="@style and contains(@style, 'font-weight:')">
1777       <xsl:variable name="font_weight" select="normalize-space(substring-after(@style, 'font-weight:'))" />
1778       <xsl:choose>
1779         <xsl:when test="contains($font_weight, ';')">
1780           <xsl:value-of select="substring-before($font_weight, ';')" />
1781         </xsl:when>
1782         <xsl:otherwise>
1783           <xsl:value-of select="$font_weight" />
1784         </xsl:otherwise>
1785       </xsl:choose>
1786     </xsl:if>
1787   </xsl:variable>
1788   <xsl:if test="$value != ''">
1789     <xsl:attribute name="FontWeight">
1790       <xsl:choose>
1791         <xsl:when test="$value &lt;= 100 or $value = 'lighter'">Thin</xsl:when>
1792         <xsl:when test="$value &gt; 100 and $value &lt;= 200">ExtraLight</xsl:when>
1793         <xsl:when test="$value &gt; 200 and $value &lt;= 300">Light</xsl:when>
1794         <xsl:when test="($value &gt; 300 and $value &lt;= 400) or $value ='normal'">Normal</xsl:when>
1795         <xsl:when test="$value &gt; 400 and $value &lt;= 500">Medium</xsl:when>
1796         <xsl:when test="$value &gt; 500 and $value &lt;= 600">SemiBold</xsl:when>
1797         <xsl:when test="($value &gt; 600 and $value &lt;= 700) or $value ='bold'">Bold</xsl:when>
1798         <xsl:when test="$value &gt; 700 and $value &lt;= 800">ExtraBold</xsl:when>
1799         <xsl:when test="$value &gt; 800 and $value &lt;= 900">Black</xsl:when>
1800         <xsl:when test="$value &gt; 900 or $value = 'bolder'">ExtraBlack</xsl:when>
1801         <xsl:otherwise>normal</xsl:otherwise>
1802       </xsl:choose>
1803     </xsl:attribute>
1804   </xsl:if>
1805 </xsl:template>
1807 <!-- 
1808   // Text font family //
1809   SVG: font-family, XAML: FontFamily
1810 -->
1811 <xsl:template mode="font_family" match="*">
1812   <xsl:variable name="value">
1813     <xsl:if test="@font-family">
1814       <xsl:value-of select="translate(@font-family, &quot;'&quot;, '')" />
1815     </xsl:if>
1816     <xsl:if test="@style and contains(@style, 'font-family:')">
1817       <xsl:variable name="font_family" select="normalize-space(substring-after(@style, 'font-family:'))" />
1818       <xsl:choose>
1819         <xsl:when test="contains($font_family, ';')">
1820           <xsl:value-of select="translate(substring-before($font_family, ';'), &quot;'&quot;, '')" />
1821         </xsl:when>
1822         <xsl:otherwise>
1823           <xsl:value-of select="translate($font_family, &quot;'&quot;, '')" />
1824         </xsl:otherwise>
1825       </xsl:choose>
1826     </xsl:if>
1827   </xsl:variable>
1828   <xsl:if test="$value != ''">
1829     <xsl:attribute name="FontFamily">
1830       <xsl:choose>
1831         <xsl:when test="$value='Sans'">Arial</xsl:when>
1832         <xsl:otherwise>
1833           <xsl:value-of select="$value" />
1834         </xsl:otherwise>
1835       </xsl:choose>
1836     </xsl:attribute>
1837   </xsl:if>
1838 </xsl:template>
1840 <!-- 
1841   // Text font style //
1842   SVG: font-style, XAML: FontStyle
1843 -->
1844 <xsl:template mode="font_style" match="*">
1845   <xsl:variable name="value">
1846     <xsl:if test="@font-style">
1847       <xsl:value-of select="@font-style" />
1848     </xsl:if>
1849     <xsl:if test="@style and contains(@style, 'font-style:')">
1850       <xsl:variable name="font_style" select="normalize-space(substring-after(@style, 'font-style:'))" />
1851       <xsl:choose>
1852         <xsl:when test="contains($font_style, ';')">
1853           <xsl:value-of select="substring-before($font_style, ';')" />
1854         </xsl:when>
1855         <xsl:otherwise>
1856           <xsl:value-of select="$font_style" />
1857         </xsl:otherwise>
1858       </xsl:choose>
1859     </xsl:if>
1860   </xsl:variable>
1861   <xsl:if test="$value != ''">
1862     <xsl:attribute name="FontStyle">
1863       <xsl:value-of select="$value" />
1864     </xsl:attribute>
1865   </xsl:if>
1866 </xsl:template>
1868 <!-- 
1869   // Text baseline shift //
1870   SVG: baseline-shift, FXG: baselineShift
1871 -->
1872 <xsl:template mode="baseline_shift" match="*">
1873   <xsl:variable name="value">
1874     <xsl:if test="@baseline-shift">
1875       <xsl:value-of select="@baseline-shift" />
1876     </xsl:if>
1877     <xsl:if test="@style and contains(@style, 'baseline-shift:') and not(contains(substring-after(@style, 'baseline-shift:'), ';'))">
1878       <xsl:value-of select="substring-after(@style, 'baseline-shift:')" />
1879     </xsl:if>
1880     <xsl:if test="@style and contains(@style, 'baseline-shift:') and contains(substring-after(@style, 'baseline-shift:'), ';')">
1881       <xsl:value-of select="substring-before(substring-after(@style, 'baseline-shift:'), ';')" />
1882     </xsl:if>   
1883   </xsl:variable>
1884   <xsl:if test="$value != ''">
1885     <xsl:attribute name="baselineShift">  
1886       <xsl:choose>
1887         <xsl:when test="$value='baseline'">0</xsl:when>
1888         <xsl:when test="$value='super'">superscript</xsl:when>
1889         <xsl:when test="$value='sub'">subscript</xsl:when>
1890         <xsl:when test="translate($value, '%', '') &lt; -1000">-1000</xsl:when>
1891         <xsl:when test="translate($value, '%', '') &gt; 1000">1000</xsl:when>
1892         <xsl:otherwise>
1893           <xsl:value-of select="translate($value, '%', '')" />
1894         </xsl:otherwise>
1895       </xsl:choose>  
1896       <xsl:if test="contains($value, '%')">%</xsl:if>
1897     </xsl:attribute>
1898   </xsl:if>
1899 </xsl:template>
1901 <!-- 
1902   // Text line height //
1903   SVG: line-height, FXG: lineHeight
1904 -->
1905 <xsl:template mode="line_height" match="*">
1906   <xsl:variable name="value">
1907     <xsl:if test="@line-height">
1908       <xsl:value-of select="@line-height" />
1909     </xsl:if>
1910     <xsl:if test="@style and contains(@style, 'line-height:')">
1911       <xsl:variable name="line_height" select="normalize-space(substring-after(@style, 'line-height:'))" />
1912       <xsl:choose>
1913         <xsl:when test="contains($line_height, ';')">
1914           <xsl:value-of select="substring-before($line_height, ';')" />
1915         </xsl:when>
1916         <xsl:otherwise>
1917           <xsl:value-of select="$line_height" />
1918         </xsl:otherwise>
1919       </xsl:choose>
1920     </xsl:if>
1921   </xsl:variable>
1922   <xsl:if test="$value != ''">
1923     <xsl:attribute name="lineHeight">
1924       <xsl:call-template name="convert_unit">
1925         <xsl:with-param name="convert_value" select="$value" />
1926       </xsl:call-template>
1927     </xsl:attribute>
1928   </xsl:if>
1929 </xsl:template>
1931 <!-- 
1932   // Text writing mode //
1933   SVG: writing-mode, FXG: blockProgression 
1934   
1935   Values inverted in FXG...
1936 -->
1937 <xsl:template mode="writing_mode" match="*">
1938   <xsl:variable name="value">
1939     <xsl:if test="@writing-mode">
1940       <xsl:value-of select="@writing-mode" />
1941     </xsl:if>
1942     <xsl:if test="@style and contains(@style, 'writing-mode:') and not(contains(substring-after(@style, 'writing-mode:'), ';'))">
1943       <xsl:value-of select="substring-after(@style, 'writing-mode:')" />
1944     </xsl:if>
1945     <xsl:if test="@style and contains(@style, 'writing-mode:') and contains(substring-after(@style, 'writing-mode:'), ';')">
1946       <xsl:value-of select="substring-before(substring-after(@style, 'writing-mode:'), ';')" />
1947     </xsl:if>   
1948   </xsl:variable>
1949   <xsl:if test="$value != ''">
1950     <xsl:attribute name="blockProgression">  
1951       <xsl:choose>
1952         <xsl:when test="$value='tb'">rl</xsl:when>
1953         <xsl:otherwise>tb</xsl:otherwise>
1954       </xsl:choose>  
1955     </xsl:attribute>
1956     <xsl:if test="$value='tb'">
1957       <xsl:attribute name="textRotation">rotate270</xsl:attribute>
1958     </xsl:if>  
1959   </xsl:if>
1960 </xsl:template>
1961   
1962 <!-- 
1963   // Text decoration //
1964   SVG: text-decoration, FXG: textDecoration, lineThrough 
1965 -->
1966 <xsl:template mode="text_decoration" match="*">
1967   <xsl:variable name="value">
1968     <xsl:if test="@text-decoration">
1969       <xsl:value-of select="@text-decoration" />
1970     </xsl:if>
1971     <xsl:if test="@style and contains(@style, 'text-decoration:') and not(contains(substring-after(@style, 'text-decoration:'), ';'))">
1972       <xsl:value-of select="substring-after(@style, 'text-decoration:')" />
1973     </xsl:if>
1974     <xsl:if test="@style and contains(@style, 'text-decoration:') and contains(substring-after(@style, 'text-decoration:'), ';')">
1975       <xsl:value-of select="substring-before(substring-after(@style, 'text-decoration:'), ';')" />
1976     </xsl:if>   
1977   </xsl:variable>
1978   <xsl:if test="$value != ''">  
1979     <xsl:choose>
1980       <xsl:when test="$value='underline'">
1981         <xsl:attribute name="textDecoration">underline</xsl:attribute>
1982       </xsl:when>
1983       <xsl:when test="$value='line-through'">
1984         <xsl:attribute name="lineThrough">true</xsl:attribute>
1985       </xsl:when>
1986     </xsl:choose>  
1987   </xsl:if>
1988 </xsl:template>
1990 <!-- 
1991   // Text fill //
1992   SVG: fill, fill-opacity, XAML: Foreground
1993 -->
1994 <xsl:template mode="text_fill" match="*">
1995   <xsl:variable name="fill">
1996     <xsl:apply-templates mode="fill" select="." />
1997   </xsl:variable>
1998   <xsl:variable name="fill_opacity">
1999     <xsl:apply-templates mode="fill_opacity" select="." />
2000   </xsl:variable>
2001   <xsl:if test="starts-with($fill, '#') or (not(starts-with($fill, 'url')) and $fill != '' and $fill != 'none')">
2002     <xsl:attribute name="Foreground">
2003       <xsl:call-template name="template_color">
2004         <xsl:with-param name="colorspec">
2005           <xsl:value-of select="$fill" />
2006         </xsl:with-param>
2007         <xsl:with-param name="opacityspec">
2008           <xsl:choose>
2009           <xsl:when test="$fill_opacity">
2010             <xsl:value-of select="$fill_opacity" />
2011           </xsl:when>
2012           <xsl:otherwise>1</xsl:otherwise>
2013           </xsl:choose>
2014         </xsl:with-param>
2015       </xsl:call-template>
2016     </xsl:attribute>
2017   </xsl:if>
2018 </xsl:template>
2020 <!-- 
2021   // Text direction //
2022   SVG: direction, unicode-bidi, FXG: direction
2023 -->
2024 <xsl:template mode="direction" match="*">
2025   <xsl:variable name="value">
2026     <xsl:if test="@direction">
2027       <xsl:value-of select="@direction" />
2028     </xsl:if>
2029     <xsl:if test="@style and contains(@style, 'direction:') and not(contains(substring-after(@style, 'direction:'), ';'))">
2030       <xsl:value-of select="substring-after(@style, 'direction:')" />
2031     </xsl:if>
2032     <xsl:if test="@style and contains(@style, 'direction:') and contains(substring-after(@style, 'direction:'), ';')">
2033       <xsl:value-of select="substring-before(substring-after(@style, 'direction:'), ';')" />
2034     </xsl:if>   
2035   </xsl:variable>
2036   <xsl:variable name="bidi">
2037     <xsl:if test="@unicode-bidi">
2038       <xsl:value-of select="@unicode-bidi" />
2039     </xsl:if>
2040     <xsl:if test="@style and contains(@style, 'unicode-bidi:') and not(contains(substring-after(@style, 'unicode-bidi:'), ';'))">
2041       <xsl:value-of select="substring-after(@style, 'unicode-bidi:')" />
2042     </xsl:if>
2043     <xsl:if test="@style and contains(@style, 'unicode-bidi:') and contains(substring-after(@style, 'unicode-bidi:'), ';')">
2044       <xsl:value-of select="substring-before(substring-after(@style, 'unicode-bidi:'), ';')" />
2045     </xsl:if>   
2046   </xsl:variable>
2048   <xsl:if test="$value != '' and ($bidi='embed' or $bidi='bidi-override')">  
2049     <xsl:attribute name="direction">
2050       <xsl:choose>
2051         <xsl:when test="$value='ltr'">ltr</xsl:when>
2052         <xsl:when test="$value='rtl'">rtl</xsl:when>
2053       </xsl:choose>  
2054     </xsl:attribute>
2055   </xsl:if>
2056 </xsl:template>
2058  <!-- 
2059   // Text size //
2060 -->
2061 <xsl:template mode="text_size" match="*">
2062   <xsl:if test="@width">
2063     <xsl:attribute name="Width">
2064       <xsl:call-template name="convert_unit">
2065         <xsl:with-param name="convert_value" select="@width" />
2066       </xsl:call-template>
2067     </xsl:attribute>
2068   </xsl:if>
2069   <xsl:if test="@height">
2070     <xsl:attribute name="Height">
2071       <xsl:call-template name="convert_unit">
2072         <xsl:with-param name="convert_value" select="@height" />
2073       </xsl:call-template>
2074     </xsl:attribute>
2075   </xsl:if>
2076 </xsl:template>
2078  <!-- 
2079   // Text position //
2080 -->
2081 <xsl:template mode="text_position" match="*">
2082   <!-- Keep the first x value only -->
2083   <xsl:if test="@x">
2084     <xsl:attribute name="Canvas.Left">
2085       <xsl:choose>
2086         <xsl:when test="contains(@x, ' ')">
2087           <xsl:call-template name="convert_unit">
2088             <xsl:with-param name="convert_value" select="substring-before(@x, ' ')" />
2089           </xsl:call-template>   
2090           </xsl:when>
2091           <xsl:otherwise>
2092           <xsl:call-template name="convert_unit">
2093             <xsl:with-param name="convert_value" select="@x" />
2094           </xsl:call-template>  
2095         </xsl:otherwise>
2096       </xsl:choose>
2097     </xsl:attribute>
2098   </xsl:if>
2099   <!-- Keep the first y value only -->
2100   <xsl:if test="@y">
2101     <xsl:attribute name="Canvas.Top">
2102       <xsl:variable name="top_val">
2103         <xsl:choose>
2104           <xsl:when test="contains(@y, ' ')">
2105             <xsl:call-template name="convert_unit">
2106               <xsl:with-param name="convert_value" select="substring-before(@y, ' ')" />
2107             </xsl:call-template>   
2108             </xsl:when>
2109             <xsl:otherwise>
2110             <xsl:call-template name="convert_unit">
2111               <xsl:with-param name="convert_value" select="@y" />
2112             </xsl:call-template>  
2113           </xsl:otherwise>
2114         </xsl:choose>
2115       </xsl:variable>
2116       <xsl:variable name="size_val">
2117         <xsl:variable name="value">
2118           <xsl:apply-templates mode="get_font_size" select="." />
2119         </xsl:variable>
2120         <xsl:choose>
2121           <xsl:when test="$value != ''">
2122             <xsl:call-template name="convert_unit">
2123               <xsl:with-param name="convert_value" select="$value" />
2124             </xsl:call-template>
2125           </xsl:when>
2126           <xsl:otherwise>12</xsl:otherwise>
2127         </xsl:choose>
2128       </xsl:variable>
2129       <xsl:if test="$top_val != '' and $size_val != ''">
2130         <xsl:value-of select="$top_val - $size_val" />
2131       </xsl:if>
2132     </xsl:attribute>
2133   </xsl:if>
2134 </xsl:template>
2136 <!-- 
2137   // Objects //
2139   * Text
2140   * Lines
2141   * Rectangle
2142   * Polygon
2143   * Polyline
2144   * Path
2145   * Ellipse
2146   * Circle
2147   * Image
2148 -->
2150 <!-- 
2151   // Text objects //
2152   SVG: text, XAML: TextBlock
2153 -->
2154 <xsl:template mode="forward" match="*[name(.) = 'text']">
2155   <TextBlock>
2156     <xsl:apply-templates mode="font_size" select="." />
2157     <xsl:apply-templates mode="font_weight" select="." />
2158     <xsl:apply-templates mode="font_family" select="." />
2159     <xsl:apply-templates mode="font_style" select="." />
2160     <xsl:apply-templates mode="text_fill" select="." />
2161     <xsl:apply-templates mode="text_size" select="." />
2162     <xsl:apply-templates mode="text_position" select="." />
2163     
2164     <xsl:if test="@text-anchor">
2165       <xsl:attribute name="HorizontalAlignment">
2166         <xsl:choose>
2167           <xsl:when test="@text-anchor = 'start'">Left</xsl:when>
2168           <xsl:when test="@text-anchor = 'middle'">Center</xsl:when>
2169           <xsl:when test="@text-anchor = 'end'">Right</xsl:when>
2170         </xsl:choose>
2171       </xsl:attribute>
2172     </xsl:if>
2173     
2174     <xsl:apply-templates mode="id" select="." />
2175     <xsl:apply-templates mode="filter_effect" select="." />
2176     <xsl:apply-templates mode="desc" select="." />
2177     <xsl:apply-templates mode="clip" select="." />
2178     <!--xsl:apply-templates mode="transform" select="." /-->
2179     <!--xsl:apply-templates mode="forward" /-->
2180     
2181     <xsl:choose>
2182       <xsl:when test="*[name(.) = 'tspan']/text()">
2183         <xsl:apply-templates mode="forward" />
2184       </xsl:when>
2185       <xsl:otherwise>
2186         <xsl:choose>
2187           <xsl:when test="@xml:space='preserve'">
2188             <xsl:copy-of select="translate(text(), '&#x9;&#xA;&#xD;', ' ')" />
2189           </xsl:when>
2190           <xsl:otherwise>
2191             <xsl:copy-of select="normalize-space(translate(text(), '&#x9;&#xA;&#xD;', ' '))" />
2192           </xsl:otherwise>
2193         </xsl:choose>  
2194       </xsl:otherwise>
2195     </xsl:choose>
2196     
2197   </TextBlock>
2198 </xsl:template>
2199  
2200 <!-- 
2201   // Line object //
2202   SVG: line, XAML: Line
2203 -->
2204 <xsl:template mode="forward" match="*[name(.) = 'line']">
2205   <Line>
2206     <xsl:if test="@x1">
2207       <xsl:attribute name="X1">
2208         <xsl:value-of select="@x1" />
2209       </xsl:attribute>
2210     </xsl:if> 
2211     <xsl:if test="@y1">
2212       <xsl:attribute name="Y1">
2213         <xsl:value-of select="@y1" />
2214       </xsl:attribute>
2215     </xsl:if> 
2216     <xsl:if test="@x2">
2217       <xsl:attribute name="X2">
2218         <xsl:value-of select="@x2" />
2219       </xsl:attribute>
2220     </xsl:if> 
2221     <xsl:if test="@y2">
2222       <xsl:attribute name="Y2">
2223         <xsl:value-of select="@y2" />
2224       </xsl:attribute>
2225     </xsl:if>
2226     <xsl:apply-templates mode="id" select="." />
2227     <xsl:apply-templates mode="template_fill" select="." />
2228     <xsl:apply-templates mode="template_stroke" select="." />
2229     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2230     <xsl:apply-templates mode="stroke_dasharray" select="." />
2231     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2232     <xsl:apply-templates mode="stroke_linejoin" select="." />
2233     <xsl:apply-templates mode="stroke_linecap" select="." />
2234     <xsl:apply-templates mode="filter_effect" select="." />
2235     <xsl:apply-templates mode="desc" select="." />
2237     <xsl:apply-templates mode="transform" select=".">
2238       <xsl:with-param name="mapped_type" select="'Line'" />
2239     </xsl:apply-templates>    
2241     <xsl:apply-templates mode="forward" />
2242   </Line>
2243 </xsl:template>
2245 <!-- 
2246   // Rectangle object //
2247   SVG: rect, XAML: Rectangle
2248 -->
2249 <xsl:template mode="forward" match="*[name(.) = 'rect']">
2250   <Rectangle>
2251     <xsl:if test="@x">
2252       <xsl:attribute name="Canvas.Left">
2253         <xsl:call-template name="convert_unit">
2254           <xsl:with-param name="convert_value" select="@x" />
2255         </xsl:call-template>
2256       </xsl:attribute>
2257     </xsl:if>
2258     <xsl:if test="@y">
2259       <xsl:attribute name="Canvas.Top">
2260         <xsl:call-template name="convert_unit">
2261           <xsl:with-param name="convert_value" select="@y" />
2262         </xsl:call-template>
2263       </xsl:attribute>
2264     </xsl:if>
2265     <xsl:if test="@width">
2266       <xsl:attribute name="Width">
2267         <xsl:call-template name="convert_unit">
2268           <xsl:with-param name="convert_value" select="@width" />
2269         </xsl:call-template>
2270       </xsl:attribute>
2271     </xsl:if>
2272     <xsl:if test="@height">
2273       <xsl:attribute name="Height">
2274         <xsl:call-template name="convert_unit">
2275           <xsl:with-param name="convert_value" select="@height" />
2276         </xsl:call-template>
2277       </xsl:attribute>
2278     </xsl:if>
2279     <xsl:if test="@rx">
2280       <xsl:attribute name="RadiusX">
2281         <xsl:value-of select="@rx" />
2282       </xsl:attribute>
2283     </xsl:if>
2284     <xsl:if test="@ry">
2285       <xsl:attribute name="RadiusY">
2286         <xsl:value-of select="@ry" />
2287       </xsl:attribute>
2288     </xsl:if>
2289     <xsl:if test="@rx and not(@ry)">
2290       <xsl:attribute name="RadiusX">
2291         <xsl:value-of select="@rx" />
2292       </xsl:attribute>
2293       <xsl:attribute name="RadiusY">
2294         <xsl:value-of select="@rx" />
2295       </xsl:attribute>
2296     </xsl:if>
2297     <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>
2299     <xsl:apply-templates mode="id" select="." />
2300     <xsl:apply-templates mode="template_fill" select="." />
2301     <xsl:apply-templates mode="template_stroke" select="." />
2302     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2303     <xsl:apply-templates mode="stroke_dasharray" select="." />
2304     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2305     <xsl:apply-templates mode="stroke_linejoin" select="." />
2306     <xsl:apply-templates mode="stroke_linecap" select="." />
2307     <xsl:apply-templates mode="filter_effect" select="." />
2308     <xsl:apply-templates mode="resources" select="." />
2309     <xsl:apply-templates mode="desc" select="." />
2310     <xsl:apply-templates mode="clip" select="." />
2312     <xsl:apply-templates mode="transform" select=".">
2313       <xsl:with-param name="mapped_type" select="'Rectangle'" />
2314     </xsl:apply-templates>
2316     <xsl:apply-templates mode="forward" />
2317   </Rectangle>
2318 </xsl:template>
2320 <!-- 
2321   // Polygon object //
2322   SVG: polygon, XAML: Polygon
2323 -->
2324 <xsl:template mode="forward" match="*[name(.) = 'polygon']">
2325   <Polygon>
2326     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>
2327     <xsl:apply-templates mode="id" select="." />
2328     <xsl:apply-templates mode="fill_rule" select="." />
2329     <xsl:apply-templates mode="template_fill" select="." />
2330     <xsl:apply-templates mode="template_stroke" select="." />
2331     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2332     <xsl:apply-templates mode="stroke_dasharray" select="." />
2333     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2334     <xsl:apply-templates mode="stroke_linejoin" select="." />
2335     <xsl:apply-templates mode="stroke_linecap" select="." />
2336     <xsl:apply-templates mode="filter_effect" select="." />
2337     <xsl:apply-templates mode="desc" select="." />
2339     <xsl:apply-templates mode="transform" select=".">
2340       <xsl:with-param name="mapped_type" select="'Polygon'" />
2341     </xsl:apply-templates>
2343     <xsl:apply-templates mode="forward" />
2344   </Polygon>
2345 </xsl:template>
2347 <!-- 
2348   // Polyline object //
2349   SVG: polyline, XAML: Polyline
2350 -->
2351 <xsl:template mode="forward" match="*[name(.) = 'polyline']">
2352   <Polyline>
2353     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>
2354     <xsl:apply-templates mode="id" select="." />
2355     <xsl:apply-templates mode="fill_rule" select="." />
2356     <xsl:apply-templates mode="template_fill" select="." />
2357     <xsl:apply-templates mode="template_stroke" select="." />
2358     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2359     <xsl:apply-templates mode="stroke_dasharray" select="." />
2360     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2361     <xsl:apply-templates mode="stroke_linejoin" select="." />
2362     <xsl:apply-templates mode="stroke_linecap" select="." />
2363     <xsl:apply-templates mode="filter_effect" select="." />
2364     <xsl:apply-templates mode="desc" select="." />
2366     <xsl:apply-templates mode="transform" select=".">
2367       <xsl:with-param name="mapped_type" select="'Polyline'" />
2368     </xsl:apply-templates>
2370     <xsl:apply-templates mode="forward" />
2371   </Polyline>
2372 </xsl:template>
2374 <!-- 
2375   // Path //
2376   SVG: path, XAML: Path
2377 -->
2378 <xsl:template mode="forward" match="*[name(.) = 'path']">
2379   <Path>
2380     <xsl:apply-templates mode="id" select="." />
2381     <xsl:apply-templates mode="template_fill" select="." />
2382     <xsl:apply-templates mode="template_stroke" select="." />
2383     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2384     <xsl:apply-templates mode="stroke_dasharray" select="." />
2385     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2386     <xsl:apply-templates mode="stroke_linejoin" select="." />
2387     <xsl:apply-templates mode="stroke_linecap" select="." />
2388     <xsl:apply-templates mode="filter_effect" select="." />
2389     <xsl:apply-templates mode="desc" select="." />
2391     <xsl:if test="@d">
2392       <xsl:choose>
2393         <xsl:when test="$silverlight_compatible = 1">
2394           <xsl:attribute name="Data">
2395             <xsl:value-of select="translate(@d , ',', ' ')" />
2396           </xsl:attribute>
2397         </xsl:when>
2398         <xsl:otherwise>
2399           <Path.Data>
2400             <PathGeometry>
2401               <xsl:attribute name="Figures">
2402                 <xsl:value-of select="translate(@d , ',', ' ')" />
2403               </xsl:attribute>
2404               <xsl:apply-templates mode="fill_rule" select="." />
2405             </PathGeometry>
2406           </Path.Data>
2407          </xsl:otherwise>
2408       </xsl:choose>
2409     </xsl:if>
2411     <xsl:apply-templates mode="transform" select=".">
2412       <xsl:with-param name="mapped_type" select="'Path'" />
2413     </xsl:apply-templates>
2415     <xsl:apply-templates mode="forward" />
2416   </Path>
2417 </xsl:template>
2419 <!-- 
2420   // Ellipse object //
2421   SVG: ellipse, XAML: Ellipse
2422 -->
2423 <xsl:template mode="forward" match="*[name(.) = 'ellipse']">
2424   <Ellipse>
2425     <xsl:variable name="cx">
2426       <xsl:choose>
2427         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>
2428         <xsl:otherwise>0</xsl:otherwise>
2429       </xsl:choose>
2430     </xsl:variable>
2431     <xsl:variable name="cy">
2432       <xsl:choose>
2433         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>
2434         <xsl:otherwise>0</xsl:otherwise>
2435       </xsl:choose>
2436     </xsl:variable>
2437     <xsl:if test="@rx">
2438       <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @rx, "#.#")' /></xsl:attribute>
2439       <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @rx, "#.#")' /></xsl:attribute>
2440     </xsl:if>
2441     <xsl:if test="@ry">
2442       <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @ry, "#.#")' /></xsl:attribute>
2443       <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @ry, "#.#")' /></xsl:attribute>
2444     </xsl:if>
2445     <xsl:apply-templates mode="id" select="." />
2446     <xsl:apply-templates mode="template_fill" select="." />
2447     <xsl:apply-templates mode="template_stroke" select="." />
2448     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2449     <xsl:apply-templates mode="stroke_dasharray" select="." />
2450     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2451     <xsl:apply-templates mode="stroke_linejoin" select="." />
2452     <xsl:apply-templates mode="stroke_linecap" select="." />
2453     <xsl:apply-templates mode="filter_effect" select="." />
2454     <xsl:apply-templates mode="desc" select="." />
2455     <xsl:apply-templates mode="clip" select="." />
2457     <xsl:apply-templates mode="transform" select=".">
2458       <xsl:with-param name="mapped_type" select="'Ellipse'" />
2459     </xsl:apply-templates>
2461     <xsl:apply-templates mode="forward" />
2462   </Ellipse>
2463 </xsl:template>
2465 <!-- 
2466   // Circle object //
2467   SVG: circle, XAML: Ellipse
2468 -->
2469 <xsl:template mode="forward" match="*[name(.) = 'circle']">
2470   <Ellipse>
2471     <xsl:variable name="cx">
2472       <xsl:choose>
2473         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>
2474         <xsl:otherwise>0</xsl:otherwise>
2475       </xsl:choose>
2476     </xsl:variable>
2477     <xsl:variable name="cy">
2478       <xsl:choose>
2479         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>
2480         <xsl:otherwise>0</xsl:otherwise>
2481       </xsl:choose>
2482     </xsl:variable>
2483     <xsl:if test="@r">
2484        <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @r, "#.#")' /></xsl:attribute>
2485        <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @r, "#.#")' /></xsl:attribute>
2486        <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>
2487        <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>
2488     </xsl:if>
2489     <xsl:apply-templates mode="id" select="." />
2490     <xsl:apply-templates mode="template_fill" select="." />
2491     <xsl:apply-templates mode="template_stroke" select="." />
2492     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2493     <xsl:apply-templates mode="stroke_dasharray" select="." />
2494     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2495     <xsl:apply-templates mode="stroke_linejoin" select="." />
2496     <xsl:apply-templates mode="stroke_linecap" select="." />
2497     <xsl:apply-templates mode="filter_effect" select="." />
2498     <xsl:apply-templates mode="desc" select="." />
2499     <xsl:apply-templates mode="clip" select="." />
2501     <xsl:apply-templates mode="transform" select=".">
2502       <xsl:with-param name="mapped_type" select="'Ellipse'" />
2503     </xsl:apply-templates>
2505     <xsl:apply-templates mode="forward" />
2506   </Ellipse>
2507 </xsl:template>
2509 <!-- 
2510   // Image object//
2511   SVG: image, FXG: Image
2512 -->
2513 <xsl:template mode="forward" match="*[name(.) = 'image']">
2514   <Image>
2515     <xsl:apply-templates mode="id" select="." />
2516     <xsl:if test="@x">
2517       <xsl:attribute name="Canvas.Left">
2518         <xsl:call-template name="convert_unit">
2519           <xsl:with-param name="convert_value" select="@x" />
2520         </xsl:call-template>
2521       </xsl:attribute>
2522     </xsl:if>
2523     <xsl:if test="@y">
2524       <xsl:attribute name="Canvas.Top">
2525         <xsl:call-template name="convert_unit">
2526           <xsl:with-param name="convert_value" select="@y" />
2527         </xsl:call-template>
2528       </xsl:attribute>
2529     </xsl:if>
2530     <xsl:apply-templates mode="desc" select="." />
2531     <xsl:apply-templates mode="clip" select="." />
2532     <xsl:if test="@xlink:href">
2533       <xsl:attribute name="Source">
2534         <xsl:value-of select="@xlink:href" />
2535       </xsl:attribute>
2536     </xsl:if>
2537     <xsl:if test="@width">
2538       <xsl:attribute name="Width">
2539         <xsl:call-template name="convert_unit">
2540           <xsl:with-param name="convert_value" select="@width" />
2541         </xsl:call-template>
2542       </xsl:attribute>
2543     </xsl:if>
2544     <xsl:if test="@height">
2545       <xsl:attribute name="Height">
2546         <xsl:call-template name="convert_unit">
2547           <xsl:with-param name="convert_value" select="@height" />
2548         </xsl:call-template>
2549       </xsl:attribute>
2550     </xsl:if>
2551     <xsl:apply-templates mode="transform" select=".">
2552       <xsl:with-param name="mapped_type" select="'Image'" />
2553     </xsl:apply-templates>
2554     <xsl:apply-templates mode="forward" />
2555   </Image>
2556 </xsl:template>
2558 <!--
2559 // Geometry //
2560 * Generic clip path template
2561 * Geometry for circle
2562 * Geometry for rectangle
2563 -->
2565 <!-- Generic clip path template -->
2566 <xsl:template mode="forward" match="*[name(.) = 'clipPath']">
2567   <xsl:apply-templates mode="geometry" />
2568 </xsl:template>
2570 <!-- Geometry for circle -->
2571 <xsl:template mode="geometry" match="*[name(.) = 'circle']">
2572   <EllipseGeometry>
2573     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>
2574     <xsl:if test="@cx and @cy"><xsl:attribute name="Center"><xsl:value-of select="concat(@cx, ',', @cy)" /></xsl:attribute></xsl:if>
2575     <xsl:if test="@r">
2576       <xsl:attribute name="RadiusX"><xsl:value-of select="@r" /></xsl:attribute>
2577       <xsl:attribute name="RadiusY"><xsl:value-of select="@r" /></xsl:attribute>
2578     </xsl:if>
2579   </EllipseGeometry>
2580 </xsl:template>
2582 <!-- Geometry for rectangle -->
2583 <xsl:template mode="geometry" match="*[name(.) = 'rect']">
2584   <RectangleGeometry>
2585     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>
2586     <!--
2587     <xsl:if test="@x"><xsl:attribute name="Canvas.Left"><xsl:value-of select="@x" /></xsl:attribute></xsl:if>
2588     <xsl:if test="@y"><xsl:attribute name="Canvas.Top"><xsl:value-of select="@y" /></xsl:attribute></xsl:if>
2589     <xsl:if test="@width"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>
2590     <xsl:if test="@height"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>
2591     <xsl:if test="@rx"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>
2592     <xsl:if test="@ry"><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>
2593     -->
2594     <xsl:attribute name="Rect"><xsl:value-of select="concat('0, 0, ', @width, ', ', @height)" /></xsl:attribute>
2595   </RectangleGeometry>
2596 </xsl:template>
2598 </xsl:stylesheet>