Code

Extensions. XAML export improvements (gradients, clipping) and minor fixes.
[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="2" />
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 @filter 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         <xsl:apply-templates mode="filter_effect" select="." />
77         <!--
78         <xsl:apply-templates mode="clip" select="." />
79         -->
80         <xsl:if test="@style and contains(@style, 'display:none')">
81           <xsl:attribute name="Visibility">Collapsed</xsl:attribute>
82         </xsl:if>
83         <xsl:if test="@style and contains(@style, 'opacity:')">
84           <xsl:attribute name="Opacity">
85             <xsl:choose>
86               <xsl:when test="contains(substring-after(@style, 'opacity:'), ';')">
87                 <xsl:value-of select="substring-before(substring-after(@style, 'opacity:'), ';')" />
88               </xsl:when>
89               <xsl:otherwise>
90                 <xsl:value-of select="substring-after(@style, 'opacity:')" />
91               </xsl:otherwise>
92             </xsl:choose>
93           </xsl:attribute>
94         </xsl:if>
95         <xsl:if test="@width and not(contains(@width, '%'))">
96           <xsl:attribute name="Width">
97             <xsl:call-template name="convert_unit">
98               <xsl:with-param name="convert_value" select="@width" />
99             </xsl:call-template>
100           </xsl:attribute>
101         </xsl:if>
102           <xsl:if test="@height and not(contains(@height, '%'))">
103           <xsl:attribute name="Height">
104             <xsl:call-template name="convert_unit">
105               <xsl:with-param name="convert_value" select="@height" />
106             </xsl:call-template>
107           </xsl:attribute>
108         </xsl:if>
109         <xsl:if test="@x">
110           <xsl:attribute name="Canvas.Left">
111             <xsl:call-template name="convert_unit">
112               <xsl:with-param name="convert_value" select="@x" />
113             </xsl:call-template>
114           </xsl:attribute></xsl:if>
115         <xsl:if test="@y">
116           <xsl:attribute name="Canvas.Top">
117             <xsl:call-template name="convert_unit">
118               <xsl:with-param name="convert_value" select="@y" />
119             </xsl:call-template>
120           </xsl:attribute>
121         </xsl:if>
122         <xsl:apply-templates mode="resources" select="." />
123         
124         <xsl:if test="@viewBox">
125           <xsl:variable name="viewBox">
126             <xsl:value-of select="normalize-space(translate(@viewBox, ',', ' '))" />
127           </xsl:variable>
128           <xsl:attribute name="Width">
129             <xsl:value-of select="substring-before(substring-after(substring-after($viewBox, ' '), ' '), ' ')" />
130           </xsl:attribute>
131           <xsl:attribute name="Height">
132             <xsl:value-of select="substring-after(substring-after(substring-after($viewBox, ' '), ' '), ' ')" />
133           </xsl:attribute>
134           <Canvas.RenderTransform>
135             <TranslateTransform>
136               <xsl:attribute name="X">
137                 <xsl:value-of select="-number(substring-before($viewBox, ' '))" />
138               </xsl:attribute>
139               <xsl:attribute name="Y">
140                 <xsl:value-of select="-number(substring-before(substring-after($viewBox, ' '), ' '))" />
141               </xsl:attribute>
142             </TranslateTransform>
143           </Canvas.RenderTransform>
144         </xsl:if>
145         <xsl:if test="@transform">
146             <xsl:apply-templates mode="transform" select=".">
147               <xsl:with-param name="mapped_type" select="'Canvas'" />
148             </xsl:apply-templates>
149             <xsl:apply-templates mode="forward" select="*" />
150         </xsl:if>
152         <xsl:if test="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">
153           <Canvas.Resources>
154             <xsl:apply-templates mode="forward" select="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']" />
155           </Canvas.Resources>
156         </xsl:if>
157         <xsl:if test="not(@transform)">
158           <xsl:apply-templates mode="forward" select="*[name(.) != 'linearGradient' and name(.) != 'radialGradient' and name(.) != 'defs' and name(.) != 'clipPath']" />
159         </xsl:if>  
160       </Canvas>
161     </xsl:when>
162     <xsl:when test="not(@transform)">
163       <xsl:apply-templates mode="forward" select="*" />
164     </xsl:when>
165   </xsl:choose>
166 </xsl:template>
168 <!-- 
169   // Transforms //
170   All the matrix, translate, rotate... stuff.
171   Fixme: XAML transforms don't show the same result as SVG ones with the same values.
173   * Parse transform
174   * Apply transform
175 -->
177 <!-- 
178   // Parse transform //
179 -->
180 <xsl:template name="parse_transform">
181   <xsl:param name="input" />
182   <xsl:choose>
183   
184     <!-- Matrix transform -->
185     <xsl:when test="starts-with($input, 'matrix(')">
186       <MatrixTransform>
187         <xsl:attribute name="Matrix">
188           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'matrix('), ')'), ',', ' '))" />
189         </xsl:attribute>
190       </MatrixTransform>
191       <xsl:call-template name="parse_transform">
192         <xsl:with-param name="input" select="substring-after($input, ') ')" />
193       </xsl:call-template>      
194     </xsl:when>
195     
196     <!-- Scale transform -->
197     <xsl:when test="starts-with($input, 'scale(')">
198       <ScaleTransform>
199         <xsl:variable name="scale" select="normalize-space(translate(substring-before(substring-after($input, 'scale('), ')'), ',', ' '))" />
200         <xsl:choose>
201           <xsl:when test="contains($scale, ' ')">
202             <xsl:attribute name="ScaleX">
203               <xsl:value-of select="substring-before($scale, ' ')" />
204             </xsl:attribute>
205             <xsl:attribute name="ScaleY">
206               <xsl:value-of select="substring-after($scale, ' ')" />
207             </xsl:attribute>
208           </xsl:when>
209           <xsl:otherwise>
210             <xsl:attribute name="ScaleX">
211               <xsl:value-of select="$scale" />
212             </xsl:attribute>
213             <xsl:attribute name="ScaleY">
214               <xsl:value-of select="$scale" />
215             </xsl:attribute>
216           </xsl:otherwise>
217         </xsl:choose>
218       </ScaleTransform>
219       <xsl:call-template name="parse_transform">
220         <xsl:with-param name="input" select="substring-after($input, ') ')" />
221       </xsl:call-template>
222     </xsl:when>
223     
224     <!-- Rotate transform -->
225     <xsl:when test="starts-with($input, 'rotate(')">
226       <RotateTransform>
227         <xsl:attribute name="Angle">
228           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'rotate('), ')'), ',', ' '))" />
229         </xsl:attribute>
230         <xsl:if test="@rx">
231           <xsl:attribute name="CenterX">
232             <xsl:value-of select="@rx" />
233           </xsl:attribute>
234         </xsl:if>
235         <xsl:if test="@ry">
236           <xsl:attribute name="CenterY">
237             <xsl:value-of select="@ry" />
238           </xsl:attribute>
239         </xsl:if>
240       </RotateTransform>
241       <xsl:call-template name="parse_transform">
242         <xsl:with-param name="input" select="substring-after($input, ') ')" />
243       </xsl:call-template>
244     </xsl:when>
245     
246     <!-- Skew transform -->
247     <xsl:when test="starts-with($input, 'skewX(')">
248       <SkewTransform>
249         <xsl:attribute name="AngleX">
250           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'skewX('), ')'), ',', ' '))" />
251         </xsl:attribute>
252         <xsl:call-template name="parse_transform">
253           <xsl:with-param name="input" select="substring-after($input, ') ')" />
254         </xsl:call-template>
255       </SkewTransform>
256     </xsl:when>
257     <xsl:when test="starts-with($input, 'skewY(')">
258       <SkewTransform>
259         <xsl:attribute name="AngleY">
260           <xsl:value-of select="normalize-space(translate(substring-before(substring-after($input, 'skewY('), ')'), ',', ' '))" />
261         </xsl:attribute>
262         <xsl:call-template name="parse_transform">
263           <xsl:with-param name="input" select="substring-after($input, ') ')" />
264         </xsl:call-template>
265       </SkewTransform>
266     </xsl:when>
267     
268     <!-- Translate transform -->
269     <xsl:when test="starts-with($input, 'translate(')">
270       <TranslateTransform>
271       <xsl:variable name="translate" select="normalize-space(translate(substring-before(substring-after($input, 'translate('), ')'), ',', ' '))" />
272         <xsl:choose>
273           <xsl:when test="contains($translate, ' ')">
274             <xsl:attribute name="X">
275               <xsl:value-of select="substring-before($translate, ' ')" />
276             </xsl:attribute>
277             <xsl:attribute name="Y">
278               <xsl:value-of select="substring-after($translate, ' ')" />
279             </xsl:attribute>
280           </xsl:when>
281           <xsl:otherwise>
282             <xsl:attribute name="X">
283               <xsl:value-of select="$translate" />
284             </xsl:attribute>
285           </xsl:otherwise>
286         </xsl:choose>
287       </TranslateTransform>
288       <xsl:call-template name="parse_transform">
289         <xsl:with-param name="input" select="substring-after($input, ') ')" />
290       </xsl:call-template>
291     </xsl:when>
292   </xsl:choose>
293 </xsl:template>
295 <!-- 
296   // Apply transform //
297 -->
298 <xsl:template mode="transform" match="*">
299   <xsl:param name="mapped_type" />
300   
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>
313     <xsl:variable name="values" select="normalize-space(translate($transform, ',', ' '))" />
314     <xsl:variable name="value1">
315       <xsl:choose>
316         <xsl:when test="contains($values, ') ')">
317           <xsl:value-of select="concat(substring-before($values, ') '), ')')" />
318         </xsl:when>
319         <xsl:otherwise>
320           <xsl:value-of select="$values" />
321         </xsl:otherwise>
322       </xsl:choose>
323     </xsl:variable>
324     <xsl:variable name="value2">
325       <xsl:if test="substring-after($values, $value1) != ''">
326         <xsl:choose>
327           <xsl:when test="contains(substring-after($values, $value1), ') ')">
328             <xsl:value-of select="normalize-space(concat(substring-before(substring-after($values, $value1), ') '), ')'))" />
329           </xsl:when>
330           <xsl:otherwise>
331             <xsl:value-of select="normalize-space(substring-after($values, $value1))" />
332           </xsl:otherwise>
333         </xsl:choose>
334       </xsl:if>
335     </xsl:variable>
336     <xsl:variable name="value3">
337       <xsl:if test="$value2 != '' and substring-after($values, $value2) != ''">
338         <xsl:choose>
339           <xsl:when test="contains(substring-after($values, $value2), ') ')">
340             <xsl:value-of select="normalize-space(concat(substring-before(substring-after($values, $value2), ') '), ')'))" />
341           </xsl:when>
342           <xsl:otherwise>
343             <xsl:value-of select="normalize-space(substring-after($values, $value2))" />
344           </xsl:otherwise>
345         </xsl:choose>
346       </xsl:if>
347     </xsl:variable>
349     <xsl:variable name="transform_nodes">
350       <xsl:if test="$value3 !=''">
351         <xsl:call-template name="parse_transform">
352           <xsl:with-param name="input" select="$value3" />
353         </xsl:call-template>
354       </xsl:if>
355       <xsl:if test="$value2 !=''">
356         <xsl:call-template name="parse_transform">
357           <xsl:with-param name="input" select="$value2" />
358         </xsl:call-template>
359       </xsl:if>
360       <xsl:if test="$value1 !=''">
361         <xsl:call-template name="parse_transform">
362           <xsl:with-param name="input" select="$value1" />
363         </xsl:call-template>
364       </xsl:if>
365     </xsl:variable>
367     <xsl:choose>
368       <xsl:when test="$mapped_type and $mapped_type != '' and not(contains($mapped_type, 'Geometry'))">
369         <xsl:element name="{$mapped_type}.RenderTransform">
370           <xsl:choose>
371             <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1">
372               <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
373             </xsl:when>
374             <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1">
375               <TransformGroup>
376                 <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
377               </TransformGroup>
378             </xsl:when>
379           </xsl:choose>
380         </xsl:element>
381       </xsl:when>
382       <xsl:when test="$mapped_type and $mapped_type != '' and contains($mapped_type, 'Geometry')">
383         <xsl:element name="{$mapped_type}.Transform">
384           <xsl:choose>
385             <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1">
386               <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
387             </xsl:when>
388             <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1">
389               <TransformGroup>
390                 <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
391               </TransformGroup>
392             </xsl:when>
393           </xsl:choose>
394         </xsl:element>
395       </xsl:when>
396       <xsl:otherwise>
397         <!-- For instance LinearGradient.Transform -->
398         <xsl:choose>
399           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1">
400             <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
401           </xsl:when>
402           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1">
403             <TransformGroup>
404               <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
405             </TransformGroup>
406           </xsl:when>
407         </xsl:choose>
408       </xsl:otherwise>
409     </xsl:choose>
410   </xsl:if>  
411 </xsl:template>
413 <!--
414   // Resources (defs) //
416   * Resources ids
417   * Generic defs template
418   * Generic filters template
419   * Filter effects
420   * Linked filter effects
421   * Absolute gradients
422   * Linear gradients
423   * Radial gradients
424   * Generic gradient stops
425   * Clipping
426 -->
428 <!-- 
429   // Resources ids //
430 -->
431 <xsl:template mode="resources" match="*">
432   <!-- should be in-depth -->
433   <xsl:if test="parent::*[name(.) = 'defs']"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>
434 </xsl:template>
436 <!--
437   // Generic defs template //
438 -->
439 <xsl:template mode="forward" match="*[name(.) = 'defs']">
440   <xsl:apply-templates mode="forward" />
441 </xsl:template>
443 <!--
444   // Generic filters template //
445   Limited to one filter (can be improved)
446 -->
447 <xsl:template mode="forward" match="*[name(.) = 'filter']">
448     <xsl:if test="count(*) = 1">
449       <xsl:apply-templates mode="forward" />
450     </xsl:if> 
451 </xsl:template>
453 <!--
454   // GaussianBlur filter effects //
455   Blur values approximated with d = floor(s * 3*sqrt(2*pi)/4 + 0.5) from:
456     http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement
457     
458   Not supported by XAML:
459   * Horizontal and vertical blur.
460 -->
461 <xsl:template mode="forward" match="*[name(.) = 'feGaussianBlur']">
462   <BlurEffect>
463     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>
464     <xsl:if test="@stdDeviation">
465       <xsl:variable name="blur" select="normalize-space(translate(@stdDeviation, ',', ' '))" />
466       <xsl:choose>
467         <xsl:when test="not(contains($blur, ' '))">
468           <xsl:attribute name="Radius">
469             <xsl:value-of select="floor($blur * 1.88 + 0.5)" />
470           </xsl:attribute>
471         </xsl:when>
472         <xsl:otherwise>
473           <xsl:attribute name="Radius">
474             <xsl:value-of select="floor(substring-before($blur, ' ') * 1.88 + 0.5)" />
475           </xsl:attribute>
476         </xsl:otherwise>
477       </xsl:choose>          
478     </xsl:if>
479   </BlurEffect>  
480 </xsl:template>
482 <!--
483   // Linked filter effect //
484   Only supports blurs
485 -->
486 <xsl:template mode="filter_effect" match="*">
487   <xsl:choose>
488     <xsl:when test="@filter and starts-with(@filter, 'url(#')">
489       <xsl:attribute name="Effect">
490         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@filter, 'url(#'), ')'), '}')" />
491       </xsl:attribute>
492     </xsl:when>
493     <xsl:when test="@style and contains(normalize-space(substring-after(translate(@style, '&quot;', ''), 'filter:')), 'url(#')">
494       <xsl:attribute name="Effect">
495         <xsl:value-of select="concat('{StaticResource ', substring-before(normalize-space(substring-after(substring-after(translate(@style, '&quot;', ''), 'filter:'), 'url(#')), ')'), '}')" />
496       </xsl:attribute>
497     </xsl:when>
498   </xsl:choose>
499 </xsl:template>
501 <!--
502   // Absolute gradients //
503   Get the calling object position in order to substract it from the absolute gradient position.
504   (XAML absolute gradients values are absolute in the gradient's space).
505 -->
506 <xsl:template mode="absolute_gradient" match="*">
507   <xsl:param name="position" />
508   <xsl:if test="@id">
509     <xsl:variable name="id" select="concat('#', @id)"/>
510     <xsl:variable name="value">
511       <xsl:for-each select="//*[contains(@style,$id) or contains(@fill,$id) or contains(@stroke,$id)]">
512         <xsl:choose>
513           <xsl:when test="$position = 'y' and @y">
514             <xsl:call-template name="convert_unit">
515               <xsl:with-param name="convert_value" select="@y" />
516             </xsl:call-template>
517           </xsl:when>
518           <xsl:when test="$position = 'x' and @x">
519             <xsl:call-template name="convert_unit">
520               <xsl:with-param name="convert_value" select="@x" />
521             </xsl:call-template>
522           </xsl:when>
523         </xsl:choose>
524       </xsl:for-each>
525     </xsl:variable>
526     <xsl:choose>
527       <xsl:when test="$value != ''">
528         <xsl:value-of select="$value"/>
529       </xsl:when>
530       <xsl:otherwise>0</xsl:otherwise>
531     </xsl:choose>
532   </xsl:if>
533 </xsl:template>
535 <!--
536   // Linear gradient //
537 -->
538 <xsl:template mode="forward" match="*[name(.) = 'linearGradient']">
539   <LinearGradientBrush>
540     <xsl:if test="@id">
541       <xsl:attribute name="x:Key">
542         <xsl:value-of select="@id" />
543       </xsl:attribute>
544     </xsl:if>
545     <xsl:attribute name="MappingMode">
546       <xsl:choose>
547         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>
548         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>
549       </xsl:choose>
550     </xsl:attribute>
551     <xsl:if test="@spreadMethod">
552       <xsl:attribute name="SpreadMethod">
553         <xsl:choose>
554           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>
555           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>
556           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>
557         </xsl:choose>
558       </xsl:attribute>
559     </xsl:if>
560     <xsl:variable name="left">
561       <xsl:choose>
562         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
563           <xsl:apply-templates mode="absolute_gradient" select=".">
564             <xsl:with-param name="position" select="'x'" />
565           </xsl:apply-templates>
566         </xsl:when>
567         <xsl:otherwise>0</xsl:otherwise>
568       </xsl:choose>
569     </xsl:variable>
570     <xsl:variable name="top">
571       <xsl:choose>
572         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
573           <xsl:apply-templates mode="absolute_gradient" select=".">
574             <xsl:with-param name="position" select="'y'" />
575           </xsl:apply-templates>
576         </xsl:when>
577         <xsl:otherwise>0</xsl:otherwise>
578       </xsl:choose>
579     </xsl:variable>
580     <xsl:choose>
581       <xsl:when test="@x1 and @y1 and @x2 and @y2">
582         <xsl:choose>
583           <xsl:when test="contains(@x1, '%') and contains(@y1, '%')">
584             <xsl:attribute name="StartPoint">
585               <xsl:value-of select="concat(substring-before(@x1, '%') div 100, ',', substring-before(@y1,'%') div 100)" />
586             </xsl:attribute>
587           </xsl:when>
588           <xsl:otherwise>
589             <xsl:attribute name="StartPoint">
590               <xsl:value-of select="concat((@x1 - $left), ',', (@y1 - $top))" />
591             </xsl:attribute>
592           </xsl:otherwise>
593         </xsl:choose>
594         <xsl:choose>
595           <xsl:when test="contains(@x2, '%') and contains(@y2, '%')">
596             <xsl:attribute name="EndPoint">
597               <xsl:value-of select="concat(substring-before(@x2, '%') div 100, ',', substring-before(@y2,'%') div 100)" />
598             </xsl:attribute>
599           </xsl:when>
600           <xsl:otherwise>
601             <xsl:attribute name="EndPoint">
602               <xsl:value-of select="concat((@x2 - $left), ',', (@y2 - $top))" />
603             </xsl:attribute>
604           </xsl:otherwise>
605         </xsl:choose>  
606       </xsl:when>
607       <xsl:otherwise>
608         <xsl:attribute name="StartPoint">
609           <xsl:value-of select="'0,0'" />
610         </xsl:attribute>
611         <xsl:attribute name="EndPoint">
612           <xsl:value-of select="'1,1'" />
613         </xsl:attribute>
614       </xsl:otherwise>
615     </xsl:choose>
616     <LinearGradientBrush.GradientStops>
617       <GradientStopCollection>
618         <xsl:choose>
619           <xsl:when test="@xlink:href">
620             <xsl:variable name="reference_id" select="@xlink:href" />
621             <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />
622           </xsl:when>
623           <xsl:otherwise>
624             <xsl:apply-templates mode="forward" />
625           </xsl:otherwise>
626         </xsl:choose>
627       </GradientStopCollection>
628     </LinearGradientBrush.GradientStops>
629     <xsl:if test="@gradientTransform">
630       <LinearGradientBrush.Transform>
631         <xsl:apply-templates mode="transform" select="." />
632       </LinearGradientBrush.Transform>
633     </xsl:if>
634   </LinearGradientBrush>
635 </xsl:template>
637 <!--
638   // Radial gradient //
639 -->
640 <xsl:template mode="forward" match="*[name(.) = 'radialGradient']">
641   <RadialGradientBrush>
642     <xsl:if test="@id">
643       <xsl:attribute name="x:Key">
644         <xsl:value-of select="@id" />
645       </xsl:attribute>
646     </xsl:if>
647     <xsl:attribute name="MappingMode">
648       <xsl:choose>
649         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>
650         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>
651       </xsl:choose>
652     </xsl:attribute>
653     <xsl:if test="@spreadMethod">
654       <xsl:attribute name="SpreadMethod">
655         <xsl:choose>
656           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>
657           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>
658           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>
659         </xsl:choose>
660       </xsl:attribute>
661     </xsl:if>
662     <xsl:variable name="left">
663       <xsl:choose>
664         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
665           <xsl:apply-templates mode="absolute_gradient" select=".">
666             <xsl:with-param name="position" select="'x'" />
667           </xsl:apply-templates>
668         </xsl:when>
669         <xsl:otherwise>0</xsl:otherwise>
670       </xsl:choose>
671     </xsl:variable>
672     <xsl:variable name="top">
673       <xsl:choose>
674         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
675           <xsl:apply-templates mode="absolute_gradient" select=".">
676             <xsl:with-param name="position" select="'y'" />
677           </xsl:apply-templates>
678         </xsl:when>
679         <xsl:otherwise>0</xsl:otherwise>
680       </xsl:choose>
681     </xsl:variable>
682     <xsl:if test="@cx and @cy">
683       <xsl:attribute name="Center">
684         <xsl:choose>
685           <xsl:when test="contains(@cx, '%') and contains(@cy, '%')">
686             <xsl:value-of select="concat(number(substring-before(@cx, '%')) div 100, ',', number(substring-before(@cy, '%')) div 100)" />
687           </xsl:when>
688           <xsl:otherwise>
689             <xsl:value-of select="concat((@cx - $left), ',', (@cy - $top))" />
690           </xsl:otherwise>
691         </xsl:choose>
692       </xsl:attribute>
693     </xsl:if>  
694     <xsl:if test="@fx and @fy">
695       <xsl:attribute name="GradientOrigin">
696         <xsl:choose>
697           <xsl:when test="contains(@fx, '%') and contains(@fy, '%')">
698             <xsl:value-of select="concat(number(substring-before(@fx, '%')) div 100, ',', number(substring-before(@fy, '%')) div 100)" />
699           </xsl:when>
700           <xsl:otherwise>
701             <xsl:value-of select="concat((@fx - $left), ',', (@fy - $top))" />
702           </xsl:otherwise>
703         </xsl:choose>
704       </xsl:attribute>
705     </xsl:if>
706     <xsl:if test="@r">
707       <xsl:choose>
708         <xsl:when test="contains(@r, '%')">
709           <xsl:attribute name="RadiusX">
710             <xsl:value-of select="number(substring-before(@r, '%')) div 100" />
711           </xsl:attribute>
712           <xsl:attribute name="RadiusY">
713             <xsl:value-of select="number(substring-before(@r, '%')) div 100" />
714           </xsl:attribute>
715         </xsl:when>
716         <xsl:otherwise>
717           <xsl:attribute name="RadiusX">
718             <xsl:value-of select="@r" />
719           </xsl:attribute>
720           <xsl:attribute name="RadiusY">
721             <xsl:value-of select="@r" />
722           </xsl:attribute>
723         </xsl:otherwise>
724       </xsl:choose>
725     </xsl:if>
726     <RadialGradientBrush.GradientStops>
727       <GradientStopCollection>
728         <xsl:choose>
729           <xsl:when test="@xlink:href">
730             <xsl:variable name="reference_id" select="@xlink:href" />
731             <xsl:apply-templates mode="forward" select="//*[name(.) = 'radialGradient' and $reference_id = concat('#', @id)]/*" />
732           </xsl:when>
733           <xsl:otherwise>
734             <xsl:apply-templates mode="forward" />
735           </xsl:otherwise>
736         </xsl:choose>
737       </GradientStopCollection>
738     </RadialGradientBrush.GradientStops>
739     <xsl:if test="@gradientTransform">
740       <RadialGradientBrush.Transform>
741         <xsl:apply-templates mode="transform" select="." />
742       </RadialGradientBrush.Transform>
743     </xsl:if>
744   </RadialGradientBrush>
745 </xsl:template>
747 <!--
748   // Gradient stop //
749 -->
750 <xsl:template mode="forward" match="*[name(.) = 'stop']">
751   <GradientStop>
752     <!--xsl:apply-templates mode="stop_opacity" select="." /-->
753     <xsl:apply-templates mode="stop_color" select="." />
754     <xsl:apply-templates mode="offset" select="." />
755     <xsl:apply-templates mode="forward" />
756   </GradientStop>
757 </xsl:template>
759 <!-- 
760   // Clipping //
761 -->
762 <xsl:template mode="clip" match="*">
763   <xsl:choose>
764     <xsl:when test="@clip-path and defs/clipPath/path/@d">
765       <xsl:attribute name="Clip">
766         <xsl:value-of select="defs/clipPath/path/@d" />
767       </xsl:attribute>
768     </xsl:when>
769     <xsl:when test="@clip-path and starts-with(@clip-path, 'url(#')">
770       <xsl:attribute name="Clip">
771         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@clip-path, 'url(#'), ')'), '}')" />
772       </xsl:attribute>
773     </xsl:when>
774     <xsl:when test="@style and contains(@style, 'clip-path:url(#')">
775       <xsl:attribute name="Clip">
776         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" />
777       </xsl:attribute>
778     </xsl:when>
779     <xsl:when test="clipPath">
780       <xsl:apply-templates mode="forward" />
781     </xsl:when>
782   </xsl:choose>
783 </xsl:template>
785 <!--
786 // Misc templates //
788   * Id converter
789   * Decimal to hexadecimal converter
790   * Unit to pixel converter
791   * Object description
792   * Title and description
793   * Switch
794   * Symbols
795   * Use
796   * RDF and foreign objects
797   * Misc ignored stuff (markers, patterns, styles)
798   * Unknows tags
799 -->
801 <!--
802   // Id converter //
803   Removes "-" from the original id
804 -->
805 <xsl:template mode="id" match="*">
806 <xsl:if test="@id">
807   <xsl:attribute name="Name"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>
808   <!--
809     <xsl:attribute name="x:Key"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>
810   -->
811 </xsl:if>
812 </xsl:template>
814 <!--
815   // Decimal to hexadecimal converter //
816 -->
817 <xsl:template name="to_hex">
818   <xsl:param name="convert" />
819   <xsl:value-of select="concat(substring('0123456789ABCDEF', 1 + floor(round($convert) div 16), 1), substring('0123456789ABCDEF', 1 + round($convert) mod 16, 1))" />
820 </xsl:template>
822 <!-- 
823   // Unit to pixel converter //
824   Values with units (except %) are converted to pixels and rounded.
825   Unknown units are kept.
826   em, ex and % not implemented
827 -->
828 <xsl:template name="convert_unit">
829   <xsl:param name="convert_value" />
830   <xsl:choose>
831     <xsl:when test="contains($convert_value, 'px')">
832       <xsl:value-of select="round(translate($convert_value, 'px', ''))" />
833     </xsl:when>
834     <xsl:when test="contains($convert_value, 'pt')">
835       <xsl:value-of select="round(translate($convert_value, 'pt', '') * 1.25)" />
836     </xsl:when>
837     <xsl:when test="contains($convert_value, 'pc')">
838       <xsl:value-of select="round(translate($convert_value, 'pc', '') * 15)" />
839     </xsl:when>
840     <xsl:when test="contains($convert_value, 'mm')">
841       <xsl:value-of select="round(translate($convert_value, 'mm', '') * 3.543307)" />
842     </xsl:when>
843     <xsl:when test="contains($convert_value, 'cm')">
844       <xsl:value-of select="round(translate($convert_value, 'cm', '') * 35.43307)" />
845     </xsl:when>
846     <xsl:when test="contains($convert_value, 'in')">
847       <xsl:value-of select="round(translate($convert_value, 'in', '') * 90)" />
848     </xsl:when>
849     <xsl:when test="contains($convert_value, 'ft')">
850       <xsl:value-of select="round(translate($convert_value, 'ft', '') * 1080)" />
851     </xsl:when>
852     <xsl:when test="not(string(number($convert_value))='NaN')">
853       <xsl:value-of select="round($convert_value)" />
854     </xsl:when>
855     <xsl:otherwise>
856       <xsl:value-of select="$convert_value" />
857     </xsl:otherwise>
858   </xsl:choose>
859 </xsl:template>
861 <!-- 
862   // Object description //
863 -->
864 <xsl:template mode="desc" match="*">
865   <xsl:if test="*[name(.) = 'desc']/text()">
866     <xsl:attribute name="Tag">
867       <xsl:value-of select="*[name(.) = 'desc']/text()" />
868     </xsl:attribute>
869   </xsl:if>
870 </xsl:template>
872 <!-- 
873   // Title and description //
874   Title is ignored and desc is converted to Tag in the mode="desc" template
875 -->
876 <xsl:template mode="forward" match="*[name(.) = 'title' or name(.) = 'desc']">
878 </xsl:template>
880 <!--
881   // Switch //
882 -->
883 <xsl:template mode="forward" match="*[name(.) = 'switch']">
884   <xsl:apply-templates mode="forward" />
885 </xsl:template>
887 <!--
888   // Symbols //
889 -->
890 <xsl:template mode="forward" match="*[name(.) = 'symbol']">
891   <Style>
892     <xsl:if test="@id">
893       <xsl:attribute name="x:Key">
894         <xsl:value-of select="@id" />
895       </xsl:attribute>
896     </xsl:if>
897     <Canvas>
898       <xsl:apply-templates mode="forward" />
899     </Canvas>
900   </Style>
901 </xsl:template>
903 <!--
904   // Use //
905   (since it is not supported by Inkscape, not implemented yet)
906 -->
907 <xsl:template mode="forward" match="*[name(.) = 'use']">
908 <!-- Errors when more than one use element share the same reference
909   <Canvas>
910     <xsl:if test="@width and not(contains(@width, '%'))">
911       <xsl:attribute name="Width">
912         <xsl:call-template name="convert_unit">
913           <xsl:with-param name="convert_value" select="@width" />
914         </xsl:call-template>
915       </xsl:attribute>
916     </xsl:if>
917       <xsl:if test="@height and not(contains(@height, '%'))">
918       <xsl:attribute name="Height">
919         <xsl:call-template name="convert_unit">
920           <xsl:with-param name="convert_value" select="@height" />
921         </xsl:call-template>
922       </xsl:attribute>
923     </xsl:if>
924     <xsl:if test="@x">
925       <xsl:attribute name="Canvas.Left">
926         <xsl:call-template name="convert_unit">
927           <xsl:with-param name="convert_value" select="@x" />
928         </xsl:call-template>
929       </xsl:attribute></xsl:if>
930     <xsl:if test="@y">
931       <xsl:attribute name="Canvas.Top">
932         <xsl:call-template name="convert_unit">
933           <xsl:with-param name="convert_value" select="@y" />
934         </xsl:call-template>
935       </xsl:attribute>
936     </xsl:if>
937     
938     <StaticResource>
939       <xsl:if test="@xlink:href">
940         <xsl:attribute name="ResourceKey">
941           <xsl:value-of select="substring-after(@xlink:href, '#')" />
942         </xsl:attribute>
943       </xsl:if>
944       <xsl:apply-templates mode="forward" />
945     </StaticResource>
946   </Canvas>
947   -->
948 </xsl:template>
950 <!--
951   // RDF and foreign objects //
952 -->
953 <xsl:template mode="forward" match="rdf:RDF | *[name(.) = 'foreignObject']">
955 </xsl:template>
957 <!--
958   // Misc ignored stuff (markers, patterns, styles) //
959 -->
960 <xsl:template mode="forward" match="*[name(.) = 'marker' or name(.) = 'pattern' or name(.) = 'style']">
962 </xsl:template>
964 <!-- 
965   // Unknown tags //
966   With generic and mode="forward" templates
967 -->
968 <xsl:template match="*">
969   <xsl:comment>
970     <xsl:value-of select="concat('Unknown tag: ', name(.))" />
971   </xsl:comment>
972 </xsl:template>
974 <xsl:template mode="forward" match="*">
975   <xsl:comment>
976     <xsl:value-of select="concat('Unknown tag: ', name(.))" />
977   </xsl:comment>
978 </xsl:template>
980 <!--
981 // Colors and patterns //
983 * Generic color template
984 * Object opacity
985 * Fill
986 * Fill opacity
987 * Fill rule
988 * Generic fill template
989 * Stroke
990 * Stroke opacity
991 * Generic stroke template
992 * Stroke width
993 * Stroke mitterlimit
994 * Stroke dasharray
995 * Stroke dashoffset
996 * Linejoin SVG to XAML converter
997 * Stroke linejoin
998 * Linecap SVG to XAML converter
999 * Stroke linecap
1000 * Gradient stop
1001 * Gradient stop opacity
1002 * Gradient stop offset
1003 * Image stretch
1004 -->
1006 <!--
1007   // Generic color template //
1008 -->
1009 <xsl:template name="template_color">
1010   <xsl:param name="colorspec" />
1011   <xsl:param name="opacityspec" />
1012   <xsl:choose>
1013     <xsl:when test="starts-with($colorspec, 'rgb(') and not(contains($colorspec , '%'))">
1014       <xsl:value-of select="'#'" />
1015       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1">
1016         <xsl:call-template name="to_hex">
1017           <xsl:with-param name="convert">
1018             <xsl:value-of select="round(number($opacityspec) * 255)" />
1019           </xsl:with-param>
1020         </xsl:call-template>
1021       </xsl:if>
1022       <xsl:call-template name="to_hex">
1023         <xsl:with-param name="convert">
1024           <xsl:value-of select="substring-before(substring-after($colorspec, 'rgb('), ',')" />
1025         </xsl:with-param>
1026       </xsl:call-template>
1027       <xsl:call-template name="to_hex">
1028         <xsl:with-param name="convert">
1029           <xsl:value-of select="substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), ',')" />
1030         </xsl:with-param>
1031       </xsl:call-template>
1032       <xsl:call-template name="to_hex">
1033         <xsl:with-param name="convert">
1034           <xsl:value-of select="substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), ')')" />
1035         </xsl:with-param>
1036       </xsl:call-template>
1037     </xsl:when>
1038     <xsl:when test="starts-with($colorspec, 'rgb(') and contains($colorspec , '%')">
1039       <xsl:value-of select="'#'" />
1040       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1">
1041         <xsl:call-template name="to_hex">
1042           <xsl:with-param name="convert">
1043             <xsl:value-of select="round(number($opacityspec) * 255)" />
1044           </xsl:with-param>
1045         </xsl:call-template>
1046       </xsl:if>
1047       <xsl:call-template name="to_hex">
1048         <xsl:with-param name="convert">
1049           <xsl:value-of select="number(substring-before(substring-after($colorspec, 'rgb('), '%,')) * 255 div 100" />
1050         </xsl:with-param>
1051       </xsl:call-template>
1052       <xsl:call-template name="to_hex">
1053         <xsl:with-param name="convert">
1054           <xsl:value-of select="number(substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), '%,')) * 255 div 100" />
1055         </xsl:with-param>
1056       </xsl:call-template>
1057       <xsl:call-template name="to_hex">
1058         <xsl:with-param name="convert">
1059           <xsl:value-of select="number(substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), '%)')) * 255 div 100" />
1060         </xsl:with-param>
1061       </xsl:call-template>
1062     </xsl:when>
1063     <xsl:when test="starts-with($colorspec, '#')">
1064       <xsl:value-of select="'#'" />
1065       <xsl:if test="$opacityspec != ''">
1066         <xsl:call-template name="to_hex">
1067           <xsl:with-param name="convert">
1068             <xsl:value-of select="round(number($opacityspec) * 255)" />
1069           </xsl:with-param>
1070         </xsl:call-template>
1071       </xsl:if>
1072       <xsl:choose>
1073         <xsl:when test="string-length(substring-after($colorspec, '#')) = 3">
1074           <xsl:variable name="colorspec3">
1075             <xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" />
1076           </xsl:variable>
1077           <xsl:value-of select="concat(substring($colorspec3, 1, 1), substring($colorspec3, 1, 1))" />
1078           <xsl:value-of select="concat(substring($colorspec3, 2, 1), substring($colorspec3, 2, 1))" />
1079           <xsl:value-of select="concat(substring($colorspec3, 3, 1), substring($colorspec3, 3, 1))" />
1080         </xsl:when>
1081         <xsl:otherwise>
1082           <xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" />
1083         </xsl:otherwise>
1084       </xsl:choose>
1085     </xsl:when>
1086     <xsl:otherwise>
1087       <xsl:variable name="named_color_hex" select="document('colors.xml')/colors/color[@name = translate($colorspec, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]/@hex" />
1088       <xsl:choose>
1089         <xsl:when test="$named_color_hex and $named_color_hex != ''">
1090           <xsl:value-of select="'#'" />
1091           <xsl:if test="$opacityspec != '' and number($opacityspec) != 1">
1092             <xsl:call-template name="to_hex">
1093               <xsl:with-param name="convert">
1094                 <xsl:value-of select="number($opacityspec) * 255" />
1095               </xsl:with-param>
1096             </xsl:call-template>
1097           </xsl:if>
1098           <xsl:value-of select="substring-after($named_color_hex, '#')" />
1099         </xsl:when>
1100         <xsl:otherwise>
1101           <xsl:value-of select="$colorspec" />
1102         </xsl:otherwise>
1103       </xsl:choose>
1104     </xsl:otherwise>
1105   </xsl:choose>
1106 </xsl:template>
1108 <!--
1109   // Object opacity //
1110 -->
1111 <xsl:template mode="object_opacity" match="*">
1112   <xsl:if test="@opacity or (@style and (contains(@style, ';opacity:') or starts-with(@style, 'opacity:')))">
1113     <xsl:variable name="value">
1114     <xsl:choose>
1115       <xsl:when test="@opacity">
1116         <xsl:value-of select="@opacity" />
1117       </xsl:when>
1118       <xsl:when test="@style and contains(@style, ';opacity:')">
1119         <xsl:variable name="Opacity" select="substring-after(@style, ';opacity:')" />
1120         <xsl:choose>
1121           <xsl:when test="contains($Opacity, ';')">
1122             <xsl:value-of select="substring-before($Opacity, ';')" />
1123           </xsl:when>
1124           <xsl:otherwise>
1125             <xsl:value-of select="$Opacity" />
1126           </xsl:otherwise>
1127         </xsl:choose>
1128       </xsl:when>
1129       <xsl:when test="@style and starts-with(@style, 'opacity:')">
1130         <xsl:variable name="Opacity" select="substring-after(@style, 'opacity:')" />
1131         <xsl:choose>
1132           <xsl:when test="contains($Opacity, ';')">
1133             <xsl:value-of select="substring-before($Opacity, ';')" />
1134           </xsl:when>
1135           <xsl:otherwise>
1136             <xsl:value-of select="$Opacity" />
1137           </xsl:otherwise>
1138         </xsl:choose>
1139       </xsl:when>
1140       <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1141         <xsl:apply-templates mode="object_opacity" select="parent::*" />
1142       </xsl:when>
1143       <xsl:otherwise>1</xsl:otherwise>
1144     </xsl:choose>
1145     </xsl:variable>
1146     <xsl:attribute name="Opacity">
1147     <xsl:choose>
1148       <xsl:when test="$value &lt; 0">0</xsl:when>
1149       <xsl:when test="$value &gt; 1">1</xsl:when>
1150       <xsl:otherwise>
1151         <xsl:value-of select="$value" />
1152       </xsl:otherwise>
1153     </xsl:choose>
1154     </xsl:attribute>
1155   </xsl:if>
1156 </xsl:template>
1158 <!--
1159   // Fill //
1160 -->
1161 <xsl:template mode="fill" match="*">
1162   <xsl:variable name="value">
1163     <xsl:choose>
1164       <xsl:when test="@fill and starts-with(normalize-space(translate(@fill, '&quot;', '')), 'url(#')">
1165         <!-- Removes unwanted characters in the color link (TODO: export to a specific template)-->
1166         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(normalize-space(translate(@fill, '&quot;', '')), 'url(#'), ')'), '}')" />
1167       </xsl:when>
1168       <xsl:when test="@fill">
1169         <xsl:value-of select="normalize-space(@fill)" />
1170       </xsl:when>
1171       <xsl:when test="@style and contains(@style, 'fill:') and starts-with(normalize-space(substring-after(translate(@style, '&quot;', ''), 'fill:')), 'url(#')">
1172         <xsl:value-of select="concat('{StaticResource ', substring-before(normalize-space(substring-after(substring-after(translate(@style, '&quot;', ''), 'fill:'), 'url(#')), ')'), '}')" />
1173       </xsl:when>
1174       <xsl:when test="@style and contains(@style, 'fill:')">
1175         <xsl:variable name="Fill" select="normalize-space(substring-after(@style, 'fill:'))" />
1176         <xsl:choose>
1177           <xsl:when test="contains($Fill, ';')">
1178             <xsl:value-of select="substring-before($Fill, ';')" />
1179           </xsl:when>
1180           <xsl:otherwise>
1181             <xsl:value-of select="$Fill" />
1182           </xsl:otherwise>
1183         </xsl:choose>
1184       </xsl:when>
1185       <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1186         <xsl:apply-templates mode="fill" select="parent::*"/>
1187       </xsl:when>
1188     </xsl:choose>
1189   </xsl:variable>
1190   <xsl:if test="$value">
1191     <xsl:value-of select="$value" />
1192   </xsl:if>
1193 </xsl:template>
1195 <!--
1196   // Fill opacity //
1197 -->
1198 <xsl:template mode="fill_opacity" match="*">
1199   <xsl:variable name="value">
1200   <xsl:choose>
1201     <xsl:when test="@fill-opacity">
1202       <xsl:value-of select="normalize-space(@fill-opacity)" />
1203     </xsl:when>
1204     <xsl:when test="@style and contains(@style, 'fill-opacity:')">
1205       <xsl:variable name="Opacity" select="normalize-space(substring-after(@style, 'fill-opacity:'))" />
1206       <xsl:choose>
1207         <xsl:when test="contains($Opacity, ';')">
1208           <xsl:value-of select="substring-before($Opacity, ';')" />
1209         </xsl:when>
1210         <xsl:otherwise>
1211           <xsl:value-of select="$Opacity" />
1212         </xsl:otherwise>
1213       </xsl:choose>
1214     </xsl:when>
1215     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1216       <xsl:apply-templates mode="fill_opacity" select="parent::*" />
1217     </xsl:when>
1218     <xsl:otherwise>1</xsl:otherwise>
1219   </xsl:choose>
1220   </xsl:variable>
1221   <xsl:choose>
1222     <xsl:when test="$value &lt; 0">0</xsl:when>
1223     <xsl:when test="$value &gt; 1">1</xsl:when>
1224     <xsl:otherwise>
1225       <xsl:value-of select="$value" />
1226     </xsl:otherwise>
1227   </xsl:choose>
1228 </xsl:template>
1230 <!--
1231   // Fill rule //
1232 -->
1233 <xsl:template mode="fill_rule" match="*">
1234   <xsl:choose>
1235     <xsl:when test="@fill-rule and (@fill-rule = 'nonzero' or @fill-rule = 'evenodd')">
1236       <xsl:attribute name="FillRule">
1237         <xsl:value-of select="normalize-space(@fill-rule)" />
1238       </xsl:attribute>
1239     </xsl:when>
1240     <xsl:when test="@style and contains(@style, 'fill-rule:')">
1241       <xsl:variable name="FillRule" select="normalize-space(substring-after(@style, 'fill-rule:'))" />
1242       <xsl:choose>
1243         <xsl:when test="contains($FillRule, ';')">
1244           <xsl:if test="substring-before($FillRule, ';') = 'nonzero' or substring-before($FillRule, ';') = 'evenodd'">
1245             <xsl:attribute name="FillRule">
1246               <xsl:value-of select="substring-before($FillRule, ';')" />
1247             </xsl:attribute>
1248           </xsl:if>
1249         </xsl:when>
1250         <xsl:when test="$FillRule = 'nonzero' or $FillRule = 'evenodd'">
1251           <xsl:attribute name="FillRule">
1252             <xsl:value-of select="$FillRule" />
1253           </xsl:attribute>
1254         </xsl:when>
1255       </xsl:choose>
1256     </xsl:when>
1257     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1258       <xsl:apply-templates mode="fill_rule" select="parent::*"/>
1259     </xsl:when>
1260     <xsl:otherwise>
1261       <xsl:attribute name="FillRule">NonZero</xsl:attribute>
1262     </xsl:otherwise>
1263   </xsl:choose>
1264 </xsl:template>
1266 <!--
1267   // Generic fill template //
1268 -->
1269 <xsl:template mode="template_fill" match="*">
1270   <xsl:variable name="fill"><xsl:apply-templates mode="fill" select="." /></xsl:variable>
1271   <xsl:variable name="fill_opacity"><xsl:apply-templates mode="fill_opacity" select="." /></xsl:variable>
1272   <xsl:if test="not($fill = 'none')">
1273     <xsl:attribute name="Fill">
1274       <xsl:choose>
1275         <xsl:when test="$fill != ''">
1276           <xsl:call-template name="template_color">
1277             <xsl:with-param name="colorspec">
1278               <xsl:if test="$fill != 'none'">
1279                 <xsl:value-of select="$fill" />
1280               </xsl:if>
1281             </xsl:with-param>
1282             <xsl:with-param name="opacityspec">
1283               <xsl:value-of select="$fill_opacity" />
1284             </xsl:with-param>
1285           </xsl:call-template>
1286         </xsl:when>
1287         <xsl:otherwise>#000000</xsl:otherwise>
1288       </xsl:choose>
1289     </xsl:attribute>
1290   </xsl:if>
1291 </xsl:template>
1293 <!--
1294   // Stroke //
1295 -->
1296 <xsl:template mode="stroke" match="*">
1297   <xsl:choose>
1298     <xsl:when test="@stroke and starts-with(@stroke, 'url(#')">
1299       <!-- Removes unwanted characters in the color link (TODO: export to a specific template)-->
1300       <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(normalize-space(translate(@stroke, '&quot;', '')), 'url(#'), ')'), '}')" />
1301     </xsl:when>
1302     <xsl:when test="@stroke and normalize-space(@stroke) != 'none'">
1303       <xsl:value-of select="@stroke" />
1304     </xsl:when>
1305     <xsl:when test="@style and contains(@style, 'stroke:') and starts-with(normalize-space(substring-after(translate(@style, '&quot;', ''), 'stroke:')), 'url(#')">
1306       <xsl:value-of select="concat('{StaticResource ', substring-before(normalize-space(substring-after(substring-after(translate(@style, '&quot;', ''), 'stroke:'), 'url(#')), ')'), '}')" />
1307     </xsl:when>
1308     <xsl:when test="@style and contains(@style, 'stroke:')">
1309       <xsl:variable name="Stroke" select="normalize-space(substring-after(@style, 'stroke:'))" />
1310       <xsl:choose>
1311         <xsl:when test="contains($Stroke, ';')">
1312           <xsl:if test="substring-before($Stroke, ';') != 'none'">
1313             <xsl:value-of select="substring-before($Stroke, ';')" />
1314           </xsl:if>
1315         </xsl:when>
1316         <xsl:when test="$Stroke != 'none'">
1317           <xsl:value-of select="$Stroke" />
1318         </xsl:when>
1319       </xsl:choose>
1320     </xsl:when>
1321     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1322       <xsl:apply-templates mode="stroke" select="parent::*"/>
1323     </xsl:when>
1324   </xsl:choose>
1325 </xsl:template>
1327 <!--
1328   // Stroke opacity //
1329 -->
1330 <xsl:template mode="stroke_opacity" match="*">
1331   <xsl:variable name="value">
1332   <xsl:choose>
1333     <xsl:when test="@stroke-opacity">
1334       <xsl:value-of select="@stroke-opacity" />
1335     </xsl:when>
1336     <xsl:when test="@style and contains(@style, 'stroke-opacity:')">
1337       <xsl:variable name="Opacity" select="substring-after(@style, 'stroke-opacity:')" />
1338       <xsl:choose>
1339         <xsl:when test="contains($Opacity, ';')">
1340           <xsl:value-of select="substring-before($Opacity, ';')" />
1341         </xsl:when>
1342         <xsl:otherwise>
1343           <xsl:value-of select="$Opacity" />
1344         </xsl:otherwise>
1345       </xsl:choose>
1346     </xsl:when>
1347     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1348       <xsl:apply-templates mode="stroke_opacity" select="parent::*" />
1349     </xsl:when>
1350     <xsl:otherwise>1</xsl:otherwise>
1351   </xsl:choose>
1352   </xsl:variable>
1353   <xsl:choose>
1354     <xsl:when test="$value &lt; 0">0</xsl:when>
1355     <xsl:when test="$value &gt; 1">1</xsl:when>
1356     <xsl:otherwise>
1357       <xsl:value-of select="$value" />
1358     </xsl:otherwise>
1359   </xsl:choose>
1360 </xsl:template>
1362 <!-- 
1363   // Generic stroke template //
1364  -->
1365 <xsl:template mode="template_stroke" match="*">
1366   <xsl:variable name="stroke">
1367     <xsl:apply-templates mode="stroke" select="." />
1368   </xsl:variable>
1369   <xsl:variable name="stroke_opacity">
1370     <xsl:apply-templates mode="stroke_opacity" select="." />
1371   </xsl:variable>
1372   <xsl:variable name="stroke_width">
1373     <xsl:apply-templates mode="stroke_width" select="." />
1374   </xsl:variable>
1375   
1376   <xsl:if test="$stroke_width != ''">
1377     <xsl:attribute name="StrokeThickness">
1378       <xsl:value-of select="$stroke_width" />
1379     </xsl:attribute>
1380   </xsl:if>
1381   <xsl:if test="$stroke != ''">
1382     <xsl:attribute name="Stroke">
1383       <xsl:call-template name="template_color">
1384         <xsl:with-param name="colorspec">
1385           <xsl:value-of select="$stroke" />
1386         </xsl:with-param>
1387         <xsl:with-param name="opacityspec">
1388           <xsl:value-of select="$stroke_opacity" />
1389         </xsl:with-param>
1390       </xsl:call-template>
1391     </xsl:attribute>
1392   </xsl:if>
1393 </xsl:template>
1395 <!--
1396   // Stroke width //
1397 -->
1398 <xsl:template mode="stroke_width" match="*">
1399   <xsl:choose>
1400     <xsl:when test="@stroke-width">
1401       <xsl:call-template name="convert_unit">
1402         <xsl:with-param name="convert_value">
1403           <xsl:value-of select="@stroke-width" />
1404         </xsl:with-param>
1405       </xsl:call-template> 
1406     </xsl:when>
1407     <xsl:when test="@style and contains(@style, 'stroke-width:')">
1408       <xsl:call-template name="convert_unit">
1409         <xsl:with-param name="convert_value">
1410         <xsl:choose>
1411           <xsl:when test="contains(substring-after(@style, 'stroke-width:'), ';')">
1412             <xsl:value-of select="substring-before(substring-after(@style, 'stroke-width:'), ';')" />
1413           </xsl:when>
1414           <xsl:otherwise>
1415             <xsl:value-of select="substring-after(@style, 'stroke-width:')" />
1416           </xsl:otherwise>
1417         </xsl:choose>
1418         </xsl:with-param>
1419       </xsl:call-template> 
1420     </xsl:when>
1421     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1422       <xsl:apply-templates mode="stroke_width" select="parent::*"/>
1423     </xsl:when>
1424   </xsl:choose>
1425 </xsl:template>
1427 <!--
1428   // Stroke miterlimit //
1429 -->
1430 <xsl:template mode="stroke_miterlimit" match="*">
1431   <xsl:choose>
1432     <xsl:when test="@stroke-miterlimit">
1433       <xsl:attribute name="StrokeMiterLimit">
1434         <xsl:value-of select="normalize-space(@stroke-miterlimit)" />
1435       </xsl:attribute>
1436     </xsl:when>
1437     <xsl:when test="@style and contains(@style, 'stroke-miterlimit:')">
1438       <xsl:variable name="StrokeMiterLimit" select="normalize-space(substring-after(@style, 'stroke-miterlimit:'))" />
1439       <xsl:attribute name="StrokeMiterLimit">
1440         <xsl:choose>
1441           <xsl:when test="contains($StrokeMiterLimit, ';')">
1442             <xsl:value-of select="substring-before($StrokeMiterLimit, ';')" />
1443           </xsl:when>
1444           <xsl:otherwise>
1445             <xsl:value-of select="$StrokeMiterLimit" />
1446           </xsl:otherwise>
1447         </xsl:choose>
1448       </xsl:attribute>
1449     </xsl:when>
1450     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1451       <xsl:apply-templates mode="stroke_miterlimit" select="parent::*"/>
1452     </xsl:when>
1453   </xsl:choose>
1454 </xsl:template>
1456 <!-- 
1457   // Stroke dasharray //
1458 -->
1459 <xsl:template mode="stroke_dasharray" match="*">
1460   <!-- stroke-dasharray="10,30,20,30" becomes StrokeDashArray="1 3 2 3" ?? -->
1461   <xsl:choose>
1462     <xsl:when test="@stroke-dasharray and normalize-space(@stroke-dasharray) != 'none'">
1463       <xsl:attribute name="StrokeDashArray">
1464         <xsl:value-of select="@stroke-dasharray" />
1465       </xsl:attribute>
1466     </xsl:when>
1467     <xsl:when test="@style and contains(@style, 'stroke-dasharray:')">
1468       <xsl:variable name="StrokeDashArray" select="substring-after(@style, 'stroke-dasharray:')" />
1469       <xsl:choose>
1470         <xsl:when test="contains($StrokeDashArray, ';')">
1471           <xsl:if test="normalize-space(substring-before($StrokeDashArray, ';')) != 'none'">
1472             <xsl:attribute name="StrokeDashArray">
1473               <xsl:value-of select="substring-before($StrokeDashArray, ';')" />
1474             </xsl:attribute>
1475           </xsl:if>
1476         </xsl:when>
1477         <xsl:when test="normalize-space($StrokeDashArray) != 'none'">
1478           <xsl:attribute name="StrokeDashArray">
1479             <xsl:value-of select="$StrokeDashArray" />
1480           </xsl:attribute>
1481         </xsl:when>
1482       </xsl:choose>
1483     </xsl:when>
1484     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1485       <xsl:apply-templates mode="stroke_dasharray" select="parent::*"/>
1486     </xsl:when>
1487   </xsl:choose>
1488 </xsl:template>
1490 <!-- 
1491   // Stroke dashoffset //
1492 -->
1493 <xsl:template mode="stroke_dashoffset" match="*">
1494   <xsl:choose>
1495     <xsl:when test="@stroke-dashoffset or (@style and contains(@style, 'stroke-dashoffset:'))">
1496       <xsl:variable name="value">
1497         <xsl:choose>
1498           <xsl:when test="@stroke-dashoffset">
1499             <xsl:call-template name="convert_unit">
1500               <xsl:with-param name="convert_value" select="normalize-space(@stroke-dashoffset)" />
1501             </xsl:call-template>
1502           </xsl:when>
1503           <xsl:when test="@style and contains(@style, 'stroke-dashoffset:')">
1504             <xsl:variable name="StrokeDashOffset" select="normalize-space(substring-after(@style, 'stroke-dashoffset:'))" />
1505             <xsl:attribute name="StrokeDashOffset">
1506               <xsl:choose>
1507                 <xsl:when test="contains($StrokeDashOffset, ';')">
1508                   <xsl:call-template name="convert_unit">
1509                     <xsl:with-param name="convert_value" select="substring-before($StrokeDashOffset, ';')" />
1510                   </xsl:call-template>
1511                 </xsl:when>
1512                 <xsl:otherwise>
1513                   <xsl:call-template name="convert_unit">
1514                     <xsl:with-param name="convert_value" select="$StrokeDashOffset" />
1515                   </xsl:call-template>
1516                 </xsl:otherwise>
1517               </xsl:choose>
1518             </xsl:attribute>
1519           </xsl:when>
1520         </xsl:choose>
1521       </xsl:variable>
1522       <xsl:if test="value != ''">
1523         <xsl:attribute name="StrokeDashOffset">
1524           <xsl:value-of select="$value" />
1525         </xsl:attribute>
1526       </xsl:if>
1527     </xsl:when>
1528     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1529       <xsl:apply-templates mode="stroke_dashoffset" select="parent::*"/>
1530     </xsl:when>
1531   </xsl:choose>
1532 </xsl:template>
1534 <!-- 
1535   // Linejoin SVG to XAML converter //
1536 -->
1537 <xsl:template name="linejoin_svg_to_xaml">
1538   <xsl:param name="linejoin" />
1539   <xsl:choose>
1540     <xsl:when test="$linejoin = 'bevel'">Bevel</xsl:when>
1541     <xsl:when test="$linejoin = 'round'">Round</xsl:when>
1542     <xsl:otherwise>Miter</xsl:otherwise>
1543   </xsl:choose>
1544 </xsl:template>
1546 <!-- 
1547   // Stroke linejoin //
1548 -->
1549 <xsl:template mode="stroke_linejoin" match="*">
1550   <xsl:choose>
1551     <xsl:when test="@stroke-linejoin">
1552       <xsl:attribute name="StrokeLineJoin">
1553         <xsl:call-template name="linejoin_svg_to_xaml">
1554           <xsl:with-param name="linejoin">
1555             <xsl:value-of select="@stroke-linejoin" />
1556           </xsl:with-param>
1557         </xsl:call-template>
1558       </xsl:attribute>
1559     </xsl:when>
1560     <xsl:when test="@style and contains(@style, 'stroke-linejoin:')">
1561       <xsl:variable name="StrokeLineJoin" select="substring-after(@style, 'stroke-linejoin:')" />
1562       <xsl:attribute name="StrokeLineJoin">
1563         <xsl:choose>
1564           <xsl:when test="contains($StrokeLineJoin, ';')">
1565             <xsl:call-template name="linejoin_svg_to_xaml">
1566               <xsl:with-param name="linejoin">
1567                 <xsl:value-of select="substring-before($StrokeLineJoin, ';')" />
1568               </xsl:with-param>
1569             </xsl:call-template>
1570           </xsl:when>
1571           <xsl:otherwise>
1572             <xsl:call-template name="linejoin_svg_to_xaml">
1573               <xsl:with-param name="linejoin">
1574                 <xsl:value-of select="$StrokeLineJoin" />
1575               </xsl:with-param>
1576             </xsl:call-template>
1577           </xsl:otherwise>
1578         </xsl:choose>
1579       </xsl:attribute>
1580     </xsl:when>
1581     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1582       <xsl:apply-templates mode="stroke_linejoin" select="parent::*"/>
1583     </xsl:when>
1584   </xsl:choose>
1585 </xsl:template>
1587 <!-- 
1588   // Linecap SVG to XAML converter //
1589 -->
1590 <xsl:template name="linecap_svg_to_xaml">
1591   <xsl:param name="linecap" />
1592   <xsl:choose>
1593     <xsl:when test="$linecap = 'round'">Round</xsl:when>
1594     <xsl:when test="$linecap = 'square'">Square</xsl:when>
1595     <xsl:otherwise>Flat</xsl:otherwise>
1596   </xsl:choose>
1597 </xsl:template>
1599 <!--
1600   // Stroke linecap //
1601 -->
1602 <xsl:template mode="stroke_linecap" match="*">
1603   <xsl:choose>
1604     <xsl:when test="@stroke-linecap">
1605       <xsl:attribute name="StrokeStartLineCap">
1606         <xsl:call-template name="linecap_svg_to_xaml">
1607           <xsl:with-param name="linecap">
1608             <xsl:value-of select="@stroke-linecap" />
1609           </xsl:with-param>
1610         </xsl:call-template>
1611       </xsl:attribute>
1612       <xsl:attribute name="StrokeEndLineCap">
1613         <xsl:call-template name="linecap_svg_to_xaml">
1614           <xsl:with-param name="linecap">
1615             <xsl:value-of select="@stroke-linecap" />
1616           </xsl:with-param>
1617         </xsl:call-template>
1618       </xsl:attribute>
1619     </xsl:when>
1620     <xsl:when test="@style and contains(@style, 'stroke-linecap:')">
1621       <xsl:variable name="StrokeStartLineCap" select="substring-after(@style, 'stroke-linecap:')" />
1622       <xsl:variable name="StrokeEndLineCap" select="substring-after(@style, 'stroke-linecap:')" />
1623       <xsl:attribute name="StrokeStartLineCap">
1624         <xsl:choose>
1625           <xsl:when test="contains($StrokeStartLineCap, ';')">
1626             <xsl:call-template name="linecap_svg_to_xaml">
1627               <xsl:with-param name="linecap">
1628                 <xsl:value-of select="substring-before($StrokeStartLineCap, ';')" />
1629               </xsl:with-param>
1630             </xsl:call-template>
1631           </xsl:when>
1632           <xsl:otherwise>
1633             <xsl:call-template name="linecap_svg_to_xaml">
1634               <xsl:with-param name="linecap">
1635                 <xsl:value-of select="$StrokeStartLineCap" />
1636               </xsl:with-param>
1637             </xsl:call-template>
1638           </xsl:otherwise>
1639         </xsl:choose>
1640       </xsl:attribute>
1641       <xsl:attribute name="StrokeEndLineCap">
1642         <xsl:choose>
1643           <xsl:when test="contains($StrokeEndLineCap, ';')">
1644             <xsl:call-template name="linecap_svg_to_xaml">
1645               <xsl:with-param name="linecap">
1646                 <xsl:value-of select="substring-before($StrokeEndLineCap, ';')" />
1647               </xsl:with-param>
1648             </xsl:call-template>
1649           </xsl:when>
1650           <xsl:otherwise>
1651             <xsl:call-template name="linecap_svg_to_xaml">
1652               <xsl:with-param name="linecap">
1653                 <xsl:value-of select="$StrokeEndLineCap" />
1654               </xsl:with-param>
1655             </xsl:call-template>
1656           </xsl:otherwise>
1657         </xsl:choose>
1658       </xsl:attribute>
1659     </xsl:when>
1660     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1661       <xsl:apply-templates mode="stroke_linecap" select="parent::*"/>
1662     </xsl:when>
1663   </xsl:choose>
1664 </xsl:template>
1666 <!-- 
1667   // Gradient stops //
1668 -->
1669 <xsl:template mode="stop_color" match="*">
1670   <xsl:variable name="Opacity">
1671     <xsl:choose>
1672       <xsl:when test="@stop-opacity">
1673         <xsl:value-of select="normalize-space(@stop-opacity)" />
1674       </xsl:when>
1675       <xsl:when test="@style and contains(@style, 'stop-opacity:')">
1676         <xsl:variable name="temp_opacity" select="normalize-space(substring-after(@style, 'stop-opacity:'))" />
1677         <xsl:choose>
1678           <xsl:when test="contains($temp_opacity, ';')">
1679             <xsl:value-of select="substring-before($temp_opacity, ';')" />
1680           </xsl:when>
1681           <xsl:otherwise>
1682             <xsl:value-of select="$temp_opacity" />
1683           </xsl:otherwise>
1684         </xsl:choose>
1685       </xsl:when>
1686       <xsl:otherwise>
1687         <xsl:value-of select="''" />
1688       </xsl:otherwise>
1689     </xsl:choose>
1690   </xsl:variable>
1691   <xsl:variable name="hex_opacity">
1692     <xsl:choose>
1693       <xsl:when test="$Opacity != ''">
1694         <xsl:call-template name="to_hex">
1695           <xsl:with-param name="convert">
1696             <xsl:value-of select="number($Opacity) * 255" />
1697           </xsl:with-param>
1698         </xsl:call-template>
1699       </xsl:when>
1700       <xsl:otherwise>
1701         <xsl:value-of select="$Opacity" />
1702       </xsl:otherwise>
1703     </xsl:choose>
1704   </xsl:variable>
1705   <xsl:variable name="stopcolor">
1706     <xsl:choose>
1707       <xsl:when test="@stop-color">
1708         <xsl:call-template name="template_color">
1709           <xsl:with-param name="colorspec">
1710             <xsl:value-of select="normalize-space(@stop-color)" />
1711           </xsl:with-param>
1712         </xsl:call-template>
1713       </xsl:when>
1714       <xsl:when test="@style and contains(@style, 'stop-color:')">
1715         <xsl:variable name="Color" select="normalize-space(substring-after(@style, 'stop-color:'))" />
1716         <xsl:choose>
1717           <xsl:when test="contains($Color, ';')">
1718             <xsl:call-template name="template_color">
1719               <xsl:with-param name="colorspec">
1720                 <xsl:value-of select="substring-before($Color, ';')" />
1721               </xsl:with-param>
1722             </xsl:call-template>
1723           </xsl:when>
1724           <xsl:otherwise>
1725             <xsl:call-template name="template_color">
1726               <xsl:with-param name="colorspec">
1727                 <xsl:value-of select="$Color" />
1728               </xsl:with-param>
1729             </xsl:call-template>
1730           </xsl:otherwise>
1731         </xsl:choose>
1732       </xsl:when>
1733       <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1734         <xsl:apply-templates mode="stop_color" select="parent::*"/>
1735       </xsl:when>
1736       <xsl:otherwise>#000000</xsl:otherwise>
1737     </xsl:choose>
1738   </xsl:variable>
1739   <xsl:attribute name="Color">
1740     <xsl:choose>
1741       <xsl:when test="$hex_opacity != '' and starts-with($stopcolor, '#')">
1742         <xsl:value-of select="concat('#', $hex_opacity, substring-after($stopcolor, '#'))" />
1743       </xsl:when>
1744       <xsl:otherwise>
1745         <xsl:value-of select="$stopcolor" />
1746       </xsl:otherwise>
1747     </xsl:choose>
1748   </xsl:attribute>
1749 </xsl:template>
1751 <!--
1752   // Gradient stop opacity //
1753 -->
1754 <xsl:template mode="stop_opacity" match="*">
1755   <xsl:choose>
1756     <xsl:when test="@stop-opacity">
1757       <xsl:attribute name="Opacity">
1758         <xsl:value-of select="@stop-opacity" />
1759       </xsl:attribute>
1760     </xsl:when>
1761     <xsl:when test="@style and contains(@style, 'stop-opacity:')">
1762       <xsl:variable name="Opacity" select="substring-after(@style, 'stop-opacity:')" />
1763       <xsl:attribute name="Opacity">
1764         <xsl:choose>
1765           <xsl:when test="contains($Opacity, ';')">
1766             <xsl:value-of select="substring-before($Opacity, ';')" />
1767           </xsl:when>
1768           <xsl:otherwise>
1769             <xsl:value-of select="$Opacity" />
1770           </xsl:otherwise>
1771         </xsl:choose>
1772       </xsl:attribute>
1773     </xsl:when>
1774     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1775       <xsl:apply-templates mode="stop_opacity" select="parent::*"/>
1776     </xsl:when>
1777   </xsl:choose>
1778 </xsl:template>
1780 <!--
1781   // Gradient stop offset //
1782 -->
1783 <xsl:template mode="offset" match="*">
1784   <xsl:choose>
1785     <xsl:when test="@offset">
1786       <xsl:attribute name="Offset">
1787         <xsl:choose>
1788           <xsl:when test="contains(@offset, '%')">
1789             <xsl:value-of select="number(substring-before(@offset, '%')) div 100" />
1790           </xsl:when>
1791           <xsl:otherwise>
1792             <xsl:value-of select="@offset" />
1793           </xsl:otherwise>
1794         </xsl:choose>
1795       </xsl:attribute>
1796     </xsl:when>
1797     <xsl:when test="@style and contains(@style, 'offset:')">
1798       <xsl:variable name="Offset" select="substring-after(@style, 'offset:')" />
1799       <xsl:attribute name="Offset">
1800         <xsl:choose>
1801           <xsl:when test="contains($Offset, '%')">
1802             <xsl:value-of select="number(substring-before($Offset, '%')) div 100" />
1803           </xsl:when>        
1804           <xsl:when test="contains($Offset, ';')">
1805             <xsl:value-of select="substring-before($Offset, ';')" />
1806           </xsl:when>
1807           <xsl:otherwise>
1808             <xsl:value-of select="$Offset" />
1809           </xsl:otherwise>
1810         </xsl:choose>
1811       </xsl:attribute>
1812     </xsl:when>
1813     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
1814       <xsl:apply-templates mode="stop_offset" select="parent::*"/>
1815     </xsl:when>
1816   </xsl:choose>
1817 </xsl:template>
1819 <!-- 
1820   // Image stretch //
1821   SVG: preserveAspectRatio, XAML: Stretch
1822 -->
1823 <xsl:template mode="image_stretch" match="*">
1824   <xsl:variable name="value">
1825     <xsl:choose>
1826       <xsl:when test="@preserveAspectRatio">
1827         <xsl:value-of select="@preserveAspectRatio" />
1828       </xsl:when>
1829       <xsl:when test="@style and contains(@style, 'preserveAspectRatio:')">
1830         <xsl:variable name="ratio" select="normalize-space(substring-after(@style, 'preserveAspectRatio:'))" />
1831         <xsl:choose>
1832           <xsl:when test="contains($ratio, ';')">
1833             <xsl:value-of select="substring-before($ratio, ';')" />
1834           </xsl:when>
1835           <xsl:otherwise>
1836             <xsl:value-of select="$ratio" />
1837           </xsl:otherwise>
1838         </xsl:choose>
1839       </xsl:when>
1840     </xsl:choose>
1841   </xsl:variable>
1842   <xsl:if test="$value = 'none'">  
1843     <xsl:attribute name="Stretch">Fill</xsl:attribute>
1844   </xsl:if>
1845 </xsl:template>
1847 <!-- 
1848   // Text specific templates //
1850   * Text tspan
1851   * Text flowPara
1852   * Text flowRegion (text frame)
1853   * Get font size
1854   * Font size
1855   * Font weight
1856   * Font family
1857   * Font style
1858   * Baseline shift
1859   * Line height
1860   * Writing mode
1861   * Text decoration
1862   * Text fill
1863   * Text direction
1864   * Text size
1865   * Text position
1866   * Text object
1867   * FlowRoot object
1868 -->
1870  <!-- 
1871   // Text span //
1872   SVG: tspan, flowSpan, XAML: Span
1873   
1874   Not supported in XAML:
1875   * span position
1876 -->
1877 <xsl:template mode="forward" match="*[name(.) = 'tspan'  or name(.) = 'flowSpan']">
1878   <Span>
1879     <xsl:if test="../@xml:space='preserve'">
1880       <xsl:attribute name="whiteSpaceCollapse">preserve</xsl:attribute>
1881     </xsl:if>
1882     <xsl:variable name="fill">
1883       <xsl:apply-templates mode="fill" select="." />
1884     </xsl:variable>
1885     <xsl:if test="starts-with($fill, '#') or (not(starts-with($fill, 'url')) and $fill != '' and $fill != 'none')">
1886       <xsl:attribute name="Foreground">
1887         <xsl:call-template name="template_color">
1888           <xsl:with-param name="colorspec">
1889             <xsl:value-of select="$fill" />
1890           </xsl:with-param>
1891         </xsl:call-template>
1892       </xsl:attribute>
1893     </xsl:if>
1894     <xsl:apply-templates mode="font_size" select="." />
1895     <xsl:apply-templates mode="font_weight" select="." />
1896     <xsl:apply-templates mode="font_family" select="." />
1897     <xsl:apply-templates mode="font_style" select="." />
1898     <xsl:apply-templates mode="text_fill" select="." />
1899     <xsl:apply-templates mode="text_decoration" select="." />
1900     <xsl:apply-templates mode="line_height" select="." />
1901     <xsl:apply-templates mode="baseline_shift" select="." />
1902     
1903     <xsl:if test="text()">
1904       <xsl:value-of select="text()" />
1905     </xsl:if>
1906   </Span>
1907 </xsl:template>
1909  <!-- 
1910   // Text flowPara //
1911   SVG: flowPara, flowDiv XAML: ?
1912   
1913 -->
1914 <xsl:template mode="forward" match="*[name(.) = 'flowPara' or name(.) = 'flowDiv']">
1915   <xsl:choose>
1916     <xsl:when test="*[name(.) = 'flowSpan']/text()">
1917       <xsl:apply-templates mode="forward" />
1918     </xsl:when>
1919     <xsl:otherwise>
1920       <xsl:choose>
1921         <xsl:when test="@xml:space='preserve'">
1922           <xsl:copy-of select="translate(text(), '&#x9;&#xA;&#xD;', ' ')" />
1923         </xsl:when>
1924         <xsl:otherwise>
1925           <xsl:copy-of select="normalize-space(translate(text(), '&#x9;&#xA;&#xD;', ' '))" />
1926         </xsl:otherwise>
1927       </xsl:choose>  
1928     </xsl:otherwise>
1929   </xsl:choose>
1930 </xsl:template>
1933  <!-- 
1934   // Text flowRegion //
1935 -->
1936 <xsl:template mode="flow_region" match="*">
1937   <xsl:apply-templates mode="text_size" select="." />
1938   <xsl:apply-templates mode="text_position" select="." />
1939 </xsl:template>
1941 <!-- 
1942   // Get text font size //
1943 -->
1944 <xsl:template mode="get_font_size" match="*">
1945   <xsl:choose>
1946     <xsl:when test="@font-size">
1947       <xsl:value-of select="@font-size" />
1948     </xsl:when>
1949     <xsl:when test="@style and contains(@style, 'font-size:')">
1950       <xsl:variable name="font_size" select="normalize-space(substring-after(@style, 'font-size:'))" />
1951       <xsl:choose>
1952         <xsl:when test="contains($font_size, ';')">
1953           <xsl:value-of select="substring-before($font_size, ';')" />
1954         </xsl:when>
1955         <xsl:otherwise>
1956           <xsl:value-of select="$font_size" />
1957         </xsl:otherwise>
1958       </xsl:choose>
1959     </xsl:when>
1960     <xsl:when test="name(..) = 'g' or name(..) = 'svg' or name(..) = 'text' or name(..) = 'flowPara' or name(..) = 'flowRoot'">
1961       <xsl:apply-templates mode="get_font_size" select="parent::*"/>
1962     </xsl:when>
1963   </xsl:choose>
1964 </xsl:template>
1966 <!-- 
1967   // Text font size //
1968   SVG: font-size, XAML: FontSize
1969 -->
1970 <xsl:template mode="font_size" match="*">
1971   <xsl:variable name="value">
1972     <xsl:apply-templates mode="get_font_size" select="." />
1973   </xsl:variable>
1974   <xsl:if test="$value != ''">
1975     <xsl:attribute name="FontSize">
1976       <xsl:call-template name="convert_unit">
1977         <xsl:with-param name="convert_value" select="$value" />
1978       </xsl:call-template>
1979     </xsl:attribute>
1980   </xsl:if>
1981   <xsl:attribute name="FontSize">
1982     <xsl:choose>
1983       <xsl:when test="$value != ''">
1984         <xsl:call-template name="convert_unit">
1985           <xsl:with-param name="convert_value" select="$value" />
1986         </xsl:call-template>
1987       </xsl:when>
1988       <xsl:otherwise>12</xsl:otherwise>
1989     </xsl:choose>
1990   </xsl:attribute>
1991 </xsl:template>
1993 <!-- 
1994   // Text font weight //
1995   SVG: font-weight, XAML: FontWeight
1996 -->
1997 <xsl:template mode="font_weight" match="*">
1998   <xsl:variable name="value">
1999     <xsl:if test="@font-weight">
2000       <xsl:value-of select="@font-weight" />
2001     </xsl:if>
2002     <xsl:if test="@style and contains(@style, 'font-weight:')">
2003       <xsl:variable name="font_weight" select="normalize-space(substring-after(@style, 'font-weight:'))" />
2004       <xsl:choose>
2005         <xsl:when test="contains($font_weight, ';')">
2006           <xsl:value-of select="substring-before($font_weight, ';')" />
2007         </xsl:when>
2008         <xsl:otherwise>
2009           <xsl:value-of select="$font_weight" />
2010         </xsl:otherwise>
2011       </xsl:choose>
2012     </xsl:if>
2013   </xsl:variable>
2014   <xsl:if test="$value != ''">
2015     <xsl:attribute name="FontWeight">
2016       <xsl:choose>
2017         <xsl:when test="$value &lt;= 100 or $value = 'lighter'">Thin</xsl:when>
2018         <xsl:when test="$value &gt; 100 and $value &lt;= 200">ExtraLight</xsl:when>
2019         <xsl:when test="$value &gt; 200 and $value &lt;= 300">Light</xsl:when>
2020         <xsl:when test="($value &gt; 300 and $value &lt;= 400) or $value ='normal'">Normal</xsl:when>
2021         <xsl:when test="$value &gt; 400 and $value &lt;= 500">Medium</xsl:when>
2022         <xsl:when test="$value &gt; 500 and $value &lt;= 600">SemiBold</xsl:when>
2023         <xsl:when test="($value &gt; 600 and $value &lt;= 700) or $value ='bold'">Bold</xsl:when>
2024         <xsl:when test="$value &gt; 700 and $value &lt;= 800">ExtraBold</xsl:when>
2025         <xsl:when test="$value &gt; 800 and $value &lt;= 900">Black</xsl:when>
2026         <xsl:when test="$value &gt; 900 or $value = 'bolder'">ExtraBlack</xsl:when>
2027         <xsl:otherwise>normal</xsl:otherwise>
2028       </xsl:choose>
2029     </xsl:attribute>
2030   </xsl:if>
2031 </xsl:template>
2033 <!-- 
2034   // Text font family //
2035   SVG: font-family, XAML: FontFamily
2036 -->
2037 <xsl:template mode="font_family" match="*">
2038   <xsl:variable name="value">
2039     <xsl:if test="@font-family">
2040       <xsl:value-of select="translate(@font-family, &quot;'&quot;, '')" />
2041     </xsl:if>
2042     <xsl:if test="@style and contains(@style, 'font-family:')">
2043       <xsl:variable name="font_family" select="normalize-space(substring-after(@style, 'font-family:'))" />
2044       <xsl:choose>
2045         <xsl:when test="contains($font_family, ';')">
2046           <xsl:value-of select="translate(substring-before($font_family, ';'), &quot;'&quot;, '')" />
2047         </xsl:when>
2048         <xsl:otherwise>
2049           <xsl:value-of select="translate($font_family, &quot;'&quot;, '')" />
2050         </xsl:otherwise>
2051       </xsl:choose>
2052     </xsl:if>
2053   </xsl:variable>
2054   <xsl:if test="$value != ''">
2055     <xsl:attribute name="FontFamily">
2056       <xsl:choose>
2057         <xsl:when test="$value='Sans'">Arial</xsl:when>
2058         <xsl:otherwise>
2059           <xsl:value-of select="$value" />
2060         </xsl:otherwise>
2061       </xsl:choose>
2062     </xsl:attribute>
2063   </xsl:if>
2064 </xsl:template>
2066 <!-- 
2067   // Text font style //
2068   SVG: font-style, XAML: FontStyle
2069 -->
2070 <xsl:template mode="font_style" match="*">
2071   <xsl:variable name="value">
2072     <xsl:if test="@font-style">
2073       <xsl:value-of select="@font-style" />
2074     </xsl:if>
2075     <xsl:if test="@style and contains(@style, 'font-style:')">
2076       <xsl:variable name="font_style" select="normalize-space(substring-after(@style, 'font-style:'))" />
2077       <xsl:choose>
2078         <xsl:when test="contains($font_style, ';')">
2079           <xsl:value-of select="substring-before($font_style, ';')" />
2080         </xsl:when>
2081         <xsl:otherwise>
2082           <xsl:value-of select="$font_style" />
2083         </xsl:otherwise>
2084       </xsl:choose>
2085     </xsl:if>
2086   </xsl:variable>
2087   <xsl:if test="$value != ''">
2088     <xsl:attribute name="FontStyle">
2089       <xsl:value-of select="$value" />
2090     </xsl:attribute>
2091   </xsl:if>
2092 </xsl:template>
2094 <!-- 
2095   // Text baseline shift //
2096   SVG: baseline-shift, XAML: BaselineAlignment
2097 -->
2098 <xsl:template mode="baseline_shift" match="*">
2099   <xsl:variable name="value">
2100     <xsl:if test="@baseline-shift">
2101       <xsl:value-of select="@baseline-shift" />
2102     </xsl:if>
2103     <xsl:if test="@style and contains(@style, 'baseline-shift:') and not(contains(substring-after(@style, 'baseline-shift:'), ';'))">
2104       <xsl:value-of select="substring-after(@style, 'baseline-shift:')" />
2105     </xsl:if>
2106     <xsl:if test="@style and contains(@style, 'baseline-shift:') and contains(substring-after(@style, 'baseline-shift:'), ';')">
2107       <xsl:value-of select="substring-before(substring-after(@style, 'baseline-shift:'), ';')" />
2108     </xsl:if>   
2109   </xsl:variable>
2110   <xsl:if test="$value = 'baseline' or $value='super' or $value='sub'">
2111     <xsl:attribute name="BaselineAlignment">  
2112       <xsl:choose>
2113         <xsl:when test="$value='baseline'">Normal</xsl:when>
2114         <xsl:when test="$value='super'">Superscript</xsl:when>
2115         <xsl:when test="$value='sub'">Subscript</xsl:when>
2116       </xsl:choose>  
2117       <xsl:if test="contains($value, '%')">%</xsl:if>
2118     </xsl:attribute>
2119   </xsl:if>
2120 </xsl:template>
2122 <!-- 
2123   // Text line height //
2124   SVG: line-height, FXG: lineHeight
2125 -->
2126 <xsl:template mode="line_height" match="*">
2127   <xsl:variable name="value">
2128     <xsl:if test="@line-height">
2129       <xsl:value-of select="@line-height" />
2130     </xsl:if>
2131     <xsl:if test="@style and contains(@style, 'line-height:')">
2132       <xsl:variable name="line_height" select="normalize-space(substring-after(@style, 'line-height:'))" />
2133       <xsl:choose>
2134         <xsl:when test="contains($line_height, ';')">
2135           <xsl:value-of select="substring-before($line_height, ';')" />
2136         </xsl:when>
2137         <xsl:otherwise>
2138           <xsl:value-of select="$line_height" />
2139         </xsl:otherwise>
2140       </xsl:choose>
2141     </xsl:if>
2142   </xsl:variable>
2143   <xsl:if test="$value != ''">
2144     <xsl:attribute name="lineHeight">
2145       <xsl:call-template name="convert_unit">
2146         <xsl:with-param name="convert_value" select="$value" />
2147       </xsl:call-template>
2148     </xsl:attribute>
2149   </xsl:if>
2150 </xsl:template>
2152 <!-- 
2153   // Text writing mode //
2154   SVG: writing-mode, FXG: blockProgression 
2155   
2156   Values inverted in FXG...
2157 -->
2158 <xsl:template mode="writing_mode" match="*">
2159   <xsl:variable name="value">
2160     <xsl:if test="@writing-mode">
2161       <xsl:value-of select="@writing-mode" />
2162     </xsl:if>
2163     <xsl:if test="@style and contains(@style, 'writing-mode:') and not(contains(substring-after(@style, 'writing-mode:'), ';'))">
2164       <xsl:value-of select="substring-after(@style, 'writing-mode:')" />
2165     </xsl:if>
2166     <xsl:if test="@style and contains(@style, 'writing-mode:') and contains(substring-after(@style, 'writing-mode:'), ';')">
2167       <xsl:value-of select="substring-before(substring-after(@style, 'writing-mode:'), ';')" />
2168     </xsl:if>   
2169   </xsl:variable>
2170   <xsl:if test="$value != ''">
2171     <xsl:attribute name="blockProgression">  
2172       <xsl:choose>
2173         <xsl:when test="$value='tb'">rl</xsl:when>
2174         <xsl:otherwise>tb</xsl:otherwise>
2175       </xsl:choose>  
2176     </xsl:attribute>
2177     <xsl:if test="$value='tb'">
2178       <xsl:attribute name="textRotation">rotate270</xsl:attribute>
2179     </xsl:if>  
2180   </xsl:if>
2181 </xsl:template>
2182   
2183 <!-- 
2184   // Text decoration //
2185   SVG: text-decoration, XAML: TextDecorations 
2186 -->
2187 <xsl:template mode="text_decoration" match="*">
2188   <xsl:variable name="value">
2189     <xsl:if test="@text-decoration">
2190       <xsl:value-of select="@text-decoration" />
2191     </xsl:if>
2192     <xsl:if test="@style and contains(@style, 'text-decoration:') and not(contains(substring-after(@style, 'text-decoration:'), ';'))">
2193       <xsl:value-of select="substring-after(@style, 'text-decoration:')" />
2194     </xsl:if>
2195     <xsl:if test="@style and contains(@style, 'text-decoration:') and contains(substring-after(@style, 'text-decoration:'), ';')">
2196       <xsl:value-of select="substring-before(substring-after(@style, 'text-decoration:'), ';')" />
2197     </xsl:if>   
2198   </xsl:variable>
2199   <xsl:if test="$value != ''">
2200     <xsl:attribute name="TextDecorations">
2201       <xsl:choose>
2202         <xsl:when test="$value='underline'">Underline</xsl:when>
2203         <xsl:when test="$value='line-through'">Strikethrough</xsl:when>
2204         <xsl:when test="$value='overline'">Overline</xsl:when>
2205         <xsl:otherwise>None</xsl:otherwise>
2206       </xsl:choose>  
2207     </xsl:attribute>
2208   </xsl:if>
2209 </xsl:template>
2211 <!-- 
2212   // Text fill //
2213   SVG: fill, fill-opacity, XAML: Foreground
2214 -->
2215 <xsl:template mode="text_fill" match="*">
2216   <xsl:variable name="fill">
2217     <xsl:apply-templates mode="fill" select="." />
2218   </xsl:variable>
2219   <xsl:variable name="fill_opacity">
2220     <xsl:apply-templates mode="fill_opacity" select="." />
2221   </xsl:variable>
2222   <xsl:if test="starts-with($fill, '#') or (not(starts-with($fill, 'url')) and $fill != '' and $fill != 'none')">
2223     <xsl:attribute name="Foreground">
2224       <xsl:call-template name="template_color">
2225         <xsl:with-param name="colorspec">
2226           <xsl:value-of select="$fill" />
2227         </xsl:with-param>
2228         <xsl:with-param name="opacityspec">
2229           <xsl:choose>
2230           <xsl:when test="$fill_opacity">
2231             <xsl:value-of select="$fill_opacity" />
2232           </xsl:when>
2233           <xsl:otherwise>1</xsl:otherwise>
2234           </xsl:choose>
2235         </xsl:with-param>
2236       </xsl:call-template>
2237     </xsl:attribute>
2238   </xsl:if>
2239 </xsl:template>
2241 <!-- 
2242   // Text direction //
2243   SVG: direction, unicode-bidi, XAML: FlowDirection
2244 -->
2245 <xsl:template mode="direction" match="*">
2246   <xsl:variable name="value">
2247     <xsl:if test="@direction">
2248       <xsl:value-of select="@direction" />
2249     </xsl:if>
2250     <xsl:if test="@style and contains(@style, 'direction:') and not(contains(substring-after(@style, 'direction:'), ';'))">
2251       <xsl:value-of select="substring-after(@style, 'direction:')" />
2252     </xsl:if>
2253     <xsl:if test="@style and contains(@style, 'direction:') and contains(substring-after(@style, 'direction:'), ';')">
2254       <xsl:value-of select="substring-before(substring-after(@style, 'direction:'), ';')" />
2255     </xsl:if>   
2256   </xsl:variable>
2257   <xsl:variable name="bidi">
2258     <xsl:if test="@unicode-bidi">
2259       <xsl:value-of select="@unicode-bidi" />
2260     </xsl:if>
2261     <xsl:if test="@style and contains(@style, 'unicode-bidi:') and not(contains(substring-after(@style, 'unicode-bidi:'), ';'))">
2262       <xsl:value-of select="substring-after(@style, 'unicode-bidi:')" />
2263     </xsl:if>
2264     <xsl:if test="@style and contains(@style, 'unicode-bidi:') and contains(substring-after(@style, 'unicode-bidi:'), ';')">
2265       <xsl:value-of select="substring-before(substring-after(@style, 'unicode-bidi:'), ';')" />
2266     </xsl:if>   
2267   </xsl:variable>
2269   <xsl:if test="$value != '' and ($bidi='embed' or $bidi='bidi-override')">  
2270     <xsl:attribute name="FlowDirection">
2271       <xsl:choose>
2272         <xsl:when test="$value='ltr'">LeftToRight</xsl:when>
2273         <xsl:when test="$value='rtl'">RightToLeft</xsl:when>
2274       </xsl:choose>  
2275     </xsl:attribute>
2276   </xsl:if>
2277 </xsl:template>
2279  <!-- 
2280   // Text size //
2281 -->
2282 <xsl:template mode="text_size" match="*">
2283   <xsl:if test="@width">
2284     <xsl:attribute name="Width">
2285       <xsl:call-template name="convert_unit">
2286         <xsl:with-param name="convert_value" select="@width" />
2287       </xsl:call-template>
2288     </xsl:attribute>
2289   </xsl:if>
2290   <xsl:if test="@height">
2291     <xsl:attribute name="Height">
2292       <xsl:call-template name="convert_unit">
2293         <xsl:with-param name="convert_value" select="@height" />
2294       </xsl:call-template>
2295     </xsl:attribute>
2296   </xsl:if>
2297 </xsl:template>
2299  <!-- 
2300   // Text position //
2301 -->
2302 <xsl:template mode="text_position" match="*">
2303   <!-- Keep the first x value only -->
2304   <xsl:if test="@x">
2305     <xsl:attribute name="Canvas.Left">
2306       <xsl:choose>
2307         <xsl:when test="contains(@x, ' ')">
2308           <xsl:call-template name="convert_unit">
2309             <xsl:with-param name="convert_value" select="substring-before(@x, ' ')" />
2310           </xsl:call-template>   
2311           </xsl:when>
2312           <xsl:otherwise>
2313           <xsl:call-template name="convert_unit">
2314             <xsl:with-param name="convert_value" select="@x" />
2315           </xsl:call-template>  
2316         </xsl:otherwise>
2317       </xsl:choose>
2318     </xsl:attribute>
2319   </xsl:if>
2320   <!-- Keep the first y value only -->
2321   <xsl:if test="@y">
2322     <xsl:attribute name="Canvas.Top">
2323       <xsl:variable name="top_val">
2324         <xsl:choose>
2325           <xsl:when test="contains(@y, ' ')">
2326             <xsl:call-template name="convert_unit">
2327               <xsl:with-param name="convert_value" select="substring-before(@y, ' ')" />
2328             </xsl:call-template>   
2329             </xsl:when>
2330             <xsl:otherwise>
2331             <xsl:call-template name="convert_unit">
2332               <xsl:with-param name="convert_value" select="@y" />
2333             </xsl:call-template>  
2334           </xsl:otherwise>
2335         </xsl:choose>
2336       </xsl:variable>
2337       <xsl:variable name="size_val">
2338         <xsl:variable name="value">
2339           <xsl:apply-templates mode="get_font_size" select="." />
2340         </xsl:variable>
2341         <xsl:choose>
2342           <xsl:when test="$value != ''">
2343             <xsl:call-template name="convert_unit">
2344               <xsl:with-param name="convert_value" select="$value" />
2345             </xsl:call-template>
2346           </xsl:when>
2347           <xsl:otherwise>12</xsl:otherwise>
2348         </xsl:choose>
2349       </xsl:variable>
2350       <xsl:if test="$top_val != '' and $size_val != ''">
2351         <xsl:value-of select="$top_val - $size_val" />
2352       </xsl:if>
2353     </xsl:attribute>
2354   </xsl:if>
2355 </xsl:template>
2357 <!-- 
2358   // Objects //
2360   * Text
2361   * Lines
2362   * Rectangle
2363   * Polygon
2364   * Polyline
2365   * Path
2366   * Ellipse
2367   * Circle
2368   * Image
2369 -->
2371 <!-- 
2372   // Text objects //
2373   SVG: text, XAML: TextBlock
2374 -->
2375 <xsl:template mode="forward" match="*[name(.) = 'text' or name(.) = 'flowRoot']">
2376   <TextBlock>
2377     <xsl:apply-templates mode="font_size" select="." />
2378     <xsl:apply-templates mode="font_weight" select="." />
2379     <xsl:apply-templates mode="font_family" select="." />
2380     <xsl:apply-templates mode="font_style" select="." />
2381     <xsl:apply-templates mode="text_fill" select="." />
2382     <xsl:apply-templates mode="text_size" select="." />
2383     <xsl:apply-templates mode="text_decoration" select="." />
2384     <xsl:apply-templates mode="direction" select="." />
2385     <xsl:apply-templates mode="text_position" select="." />
2386     <xsl:if test="name(.) = 'flowRoot'">
2387       <xsl:attribute name="TextWrapping">
2388         <xsl:value-of select="'Wrap'" />
2389       </xsl:attribute>
2390     </xsl:if>
2391     
2392     <xsl:if test="@text-anchor">
2393       <xsl:attribute name="HorizontalAlignment">
2394         <xsl:choose>
2395           <xsl:when test="@text-anchor = 'start'">Left</xsl:when>
2396           <xsl:when test="@text-anchor = 'middle'">Center</xsl:when>
2397           <xsl:when test="@text-anchor = 'end'">Right</xsl:when>
2398         </xsl:choose>
2399       </xsl:attribute>
2400     </xsl:if>
2401     
2402     <xsl:apply-templates mode="object_opacity" select="." />
2403     
2404     <xsl:apply-templates mode="id" select="." />
2405     <xsl:if test="name(.) = 'flowRoot'">
2406       <xsl:apply-templates mode="flow_region" select="*[name(.) = 'flowRegion']/child::node()" />
2407     </xsl:if>
2408     <xsl:apply-templates mode="filter_effect" select="." />
2409     <xsl:apply-templates mode="desc" select="." />
2410     <xsl:apply-templates mode="resources" select="." />
2411     <xsl:apply-templates mode="clip" select="." />
2412     <!--xsl:apply-templates mode="transform" select="." /-->
2413     <!--xsl:apply-templates mode="forward" /-->
2414     
2415     <xsl:choose>
2416       <xsl:when test="*[name(.) = 'tspan' or name(.) = 'flowPara' or name(.) = 'flowDiv']/text()">
2417         <xsl:apply-templates mode="forward" />
2418       </xsl:when>
2419       <xsl:otherwise>
2420         <xsl:choose>
2421           <xsl:when test="@xml:space='preserve'">
2422             <xsl:copy-of select="translate(text(), '&#x9;&#xA;&#xD;', ' ')" />
2423           </xsl:when>
2424           <xsl:otherwise>
2425             <xsl:copy-of select="normalize-space(translate(text(), '&#x9;&#xA;&#xD;', ' '))" />
2426           </xsl:otherwise>
2427         </xsl:choose>  
2428       </xsl:otherwise>
2429     </xsl:choose>
2430     
2431   </TextBlock>
2432 </xsl:template>
2433  
2434 <!-- 
2435   // Line object //
2436   SVG: line, XAML: Line
2437 -->
2438 <xsl:template mode="forward" match="*[name(.) = 'line']">
2439   <Line>
2440     <xsl:if test="@x1">
2441       <xsl:attribute name="X1">
2442         <xsl:value-of select="@x1" />
2443       </xsl:attribute>
2444     </xsl:if> 
2445     <xsl:if test="@y1">
2446       <xsl:attribute name="Y1">
2447         <xsl:value-of select="@y1" />
2448       </xsl:attribute>
2449     </xsl:if> 
2450     <xsl:if test="@x2">
2451       <xsl:attribute name="X2">
2452         <xsl:value-of select="@x2" />
2453       </xsl:attribute>
2454     </xsl:if> 
2455     <xsl:if test="@y2">
2456       <xsl:attribute name="Y2">
2457         <xsl:value-of select="@y2" />
2458       </xsl:attribute>
2459     </xsl:if>
2460     
2461     <xsl:apply-templates mode="id" select="." />
2462     <xsl:apply-templates mode="template_fill" select="." />
2463     <xsl:apply-templates mode="template_stroke" select="." />
2464     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2465     <xsl:apply-templates mode="stroke_dasharray" select="." />
2466     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2467     <xsl:apply-templates mode="stroke_linejoin" select="." />
2468     <xsl:apply-templates mode="stroke_linecap" select="." />
2469     <xsl:apply-templates mode="filter_effect" select="." />
2470     <xsl:apply-templates mode="object_opacity" select="." />
2471     <xsl:apply-templates mode="desc" select="." />
2472     <xsl:apply-templates mode="resources" select="." />
2474     <xsl:apply-templates mode="transform" select=".">
2475       <xsl:with-param name="mapped_type" select="'Line'" />
2476     </xsl:apply-templates>    
2478     <xsl:apply-templates mode="forward" />
2479   </Line>
2480 </xsl:template>
2482 <!-- 
2483   // Rectangle object //
2484   SVG: rect, XAML: Rectangle
2485 -->
2486 <xsl:template mode="forward" match="*[name(.) = 'rect']">
2487   <Rectangle>
2488     <xsl:if test="@x">
2489       <xsl:attribute name="Canvas.Left">
2490         <xsl:call-template name="convert_unit">
2491           <xsl:with-param name="convert_value" select="@x" />
2492         </xsl:call-template>
2493       </xsl:attribute>
2494     </xsl:if>
2495     <xsl:if test="@y">
2496       <xsl:attribute name="Canvas.Top">
2497         <xsl:call-template name="convert_unit">
2498           <xsl:with-param name="convert_value" select="@y" />
2499         </xsl:call-template>
2500       </xsl:attribute>
2501     </xsl:if>
2502     <xsl:if test="@width">
2503       <xsl:attribute name="Width">
2504         <xsl:call-template name="convert_unit">
2505           <xsl:with-param name="convert_value" select="@width" />
2506         </xsl:call-template>
2507       </xsl:attribute>
2508     </xsl:if>
2509     <xsl:if test="@height">
2510       <xsl:attribute name="Height">
2511         <xsl:call-template name="convert_unit">
2512           <xsl:with-param name="convert_value" select="@height" />
2513         </xsl:call-template>
2514       </xsl:attribute>
2515     </xsl:if>
2516     <xsl:if test="@rx">
2517       <xsl:attribute name="RadiusX">
2518         <xsl:value-of select="@rx" />
2519       </xsl:attribute>
2520     </xsl:if>
2521     <xsl:if test="@ry">
2522       <xsl:attribute name="RadiusY">
2523         <xsl:value-of select="@ry" />
2524       </xsl:attribute>
2525     </xsl:if>
2526     <xsl:if test="@rx and not(@ry)">
2527       <xsl:attribute name="RadiusX">
2528         <xsl:value-of select="@rx" />
2529       </xsl:attribute>
2530       <xsl:attribute name="RadiusY">
2531         <xsl:value-of select="@rx" />
2532       </xsl:attribute>
2533     </xsl:if>
2534     <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>
2536     <xsl:apply-templates mode="id" select="." />
2537     <xsl:apply-templates mode="template_fill" select="." />
2538     <xsl:apply-templates mode="template_stroke" select="." />
2539     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2540     <xsl:apply-templates mode="stroke_dasharray" select="." />
2541     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2542     <xsl:apply-templates mode="stroke_linejoin" select="." />
2543     <xsl:apply-templates mode="stroke_linecap" select="." />
2544     <xsl:apply-templates mode="filter_effect" select="." />
2545     <xsl:apply-templates mode="resources" select="." />
2546     <xsl:apply-templates mode="object_opacity" select="." />
2547     <xsl:apply-templates mode="desc" select="." />
2548     <xsl:apply-templates mode="clip" select="." />
2550     <xsl:apply-templates mode="transform" select=".">
2551       <xsl:with-param name="mapped_type" select="'Rectangle'" />
2552     </xsl:apply-templates>
2554     <xsl:apply-templates mode="forward" />
2555   </Rectangle>
2556 </xsl:template>
2558 <!-- 
2559   // Polygon object //
2560   SVG: polygon, XAML: Polygon
2561 -->
2562 <xsl:template mode="forward" match="*[name(.) = 'polygon']">
2563   <Polygon>
2564     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>
2565     <xsl:apply-templates mode="id" select="." />
2566     <xsl:apply-templates mode="fill_rule" select="." />
2567     <xsl:apply-templates mode="template_fill" select="." />
2568     <xsl:apply-templates mode="template_stroke" select="." />
2569     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2570     <xsl:apply-templates mode="stroke_dasharray" select="." />
2571     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2572     <xsl:apply-templates mode="stroke_linejoin" select="." />
2573     <xsl:apply-templates mode="stroke_linecap" select="." />
2574     <xsl:apply-templates mode="filter_effect" select="." />
2575     <xsl:apply-templates mode="object_opacity" select="." />
2576     <xsl:apply-templates mode="desc" select="." />
2577     <xsl:apply-templates mode="resources" select="." />
2579     <xsl:apply-templates mode="transform" select=".">
2580       <xsl:with-param name="mapped_type" select="'Polygon'" />
2581     </xsl:apply-templates>
2583     <xsl:apply-templates mode="forward" />
2584   </Polygon>
2585 </xsl:template>
2587 <!-- 
2588   // Polyline object //
2589   SVG: polyline, XAML: Polyline
2590 -->
2591 <xsl:template mode="forward" match="*[name(.) = 'polyline']">
2592   <Polyline>
2593     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>
2594     <xsl:apply-templates mode="id" select="." />
2595     <xsl:apply-templates mode="fill_rule" select="." />
2596     <xsl:apply-templates mode="template_fill" select="." />
2597     <xsl:apply-templates mode="template_stroke" select="." />
2598     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2599     <xsl:apply-templates mode="stroke_dasharray" select="." />
2600     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2601     <xsl:apply-templates mode="stroke_linejoin" select="." />
2602     <xsl:apply-templates mode="stroke_linecap" select="." />
2603     <xsl:apply-templates mode="filter_effect" select="." />
2604     <xsl:apply-templates mode="object_opacity" select="." />
2605     <xsl:apply-templates mode="desc" select="." />
2607     <xsl:apply-templates mode="transform" select=".">
2608       <xsl:with-param name="mapped_type" select="'Polyline'" />
2609     </xsl:apply-templates>
2611     <xsl:apply-templates mode="forward" />
2612   </Polyline>
2613 </xsl:template>
2615 <!-- 
2616   // Path //
2617   SVG: path, XAML: Path
2618 -->
2619 <xsl:template mode="forward" match="*[name(.) = 'path']">
2620   <Path>
2621     <xsl:apply-templates mode="id" select="." />
2622     <xsl:apply-templates mode="template_fill" select="." />
2623     <xsl:apply-templates mode="template_stroke" select="." />
2624     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2625     <xsl:apply-templates mode="stroke_dasharray" select="." />
2626     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2627     <xsl:apply-templates mode="stroke_linejoin" select="." />
2628     <xsl:apply-templates mode="stroke_linecap" select="." />
2629     <xsl:apply-templates mode="filter_effect" select="." />
2630     <xsl:apply-templates mode="object_opacity" select="." />
2631     <xsl:apply-templates mode="desc" select="." />
2632     <xsl:apply-templates mode="resources" select="." />
2633     <xsl:apply-templates mode="clip" select="." />
2634     
2635     <xsl:if test="@d">
2636       <xsl:choose>
2637         <xsl:when test="$silverlight_compatible = 1">
2638           <xsl:attribute name="Data">
2639             <xsl:value-of select="translate(@d , ',', ' ')" />
2640           </xsl:attribute>
2641         </xsl:when>
2642         <xsl:otherwise>
2643           <Path.Data>
2644             <PathGeometry>
2645               <xsl:attribute name="Figures">
2646                 <xsl:value-of select="translate(@d , ',', ' ')" />
2647               </xsl:attribute>
2648               <xsl:apply-templates mode="fill_rule" select="." />
2649             </PathGeometry>
2650           </Path.Data>
2651          </xsl:otherwise>
2652       </xsl:choose>
2653     </xsl:if>
2655     <xsl:apply-templates mode="transform" select=".">
2656       <xsl:with-param name="mapped_type" select="'Path'" />
2657     </xsl:apply-templates>
2659     <xsl:apply-templates mode="forward" />
2660   </Path>
2661 </xsl:template>
2663 <!-- 
2664   // Ellipse object //
2665   SVG: ellipse, XAML: Ellipse
2666 -->
2667 <xsl:template mode="forward" match="*[name(.) = 'ellipse']">
2668   <Ellipse>
2669     <xsl:variable name="cx">
2670       <xsl:choose>
2671         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>
2672         <xsl:otherwise>0</xsl:otherwise>
2673       </xsl:choose>
2674     </xsl:variable>
2675     <xsl:variable name="cy">
2676       <xsl:choose>
2677         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>
2678         <xsl:otherwise>0</xsl:otherwise>
2679       </xsl:choose>
2680     </xsl:variable>
2681     <xsl:if test="@rx">
2682       <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @rx, "#.#")' /></xsl:attribute>
2683       <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @rx, "#.#")' /></xsl:attribute>
2684     </xsl:if>
2685     <xsl:if test="@ry">
2686       <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @ry, "#.#")' /></xsl:attribute>
2687       <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @ry, "#.#")' /></xsl:attribute>
2688     </xsl:if>
2689     <xsl:apply-templates mode="id" select="." />
2690     <xsl:apply-templates mode="template_fill" select="." />
2691     <xsl:apply-templates mode="template_stroke" select="." />
2692     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2693     <xsl:apply-templates mode="stroke_dasharray" select="." />
2694     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2695     <xsl:apply-templates mode="stroke_linejoin" select="." />
2696     <xsl:apply-templates mode="stroke_linecap" select="." />
2697     <xsl:apply-templates mode="filter_effect" select="." />
2698     <xsl:apply-templates mode="object_opacity" select="." />
2699     <xsl:apply-templates mode="desc" select="." />
2700     <xsl:apply-templates mode="resources" select="." />
2701     <xsl:apply-templates mode="clip" select="." />
2703     <xsl:apply-templates mode="transform" select=".">
2704       <xsl:with-param name="mapped_type" select="'Ellipse'" />
2705     </xsl:apply-templates>
2707     <xsl:apply-templates mode="forward" />
2708   </Ellipse>
2709 </xsl:template>
2711 <!-- 
2712   // Circle object //
2713   SVG: circle, XAML: Ellipse
2714 -->
2715 <xsl:template mode="forward" match="*[name(.) = 'circle']">
2716   <Ellipse>
2717     <xsl:variable name="cx">
2718       <xsl:choose>
2719         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>
2720         <xsl:otherwise>0</xsl:otherwise>
2721       </xsl:choose>
2722     </xsl:variable>
2723     <xsl:variable name="cy">
2724       <xsl:choose>
2725         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>
2726         <xsl:otherwise>0</xsl:otherwise>
2727       </xsl:choose>
2728     </xsl:variable>
2729     <xsl:if test="@r">
2730        <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @r, "#.#")' /></xsl:attribute>
2731        <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @r, "#.#")' /></xsl:attribute>
2732        <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>
2733        <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>
2734     </xsl:if>
2735     <xsl:apply-templates mode="id" select="." />
2736     <xsl:apply-templates mode="template_fill" select="." />
2737     <xsl:apply-templates mode="template_stroke" select="." />
2738     <xsl:apply-templates mode="stroke_miterlimit" select="." />
2739     <xsl:apply-templates mode="stroke_dasharray" select="." />
2740     <xsl:apply-templates mode="stroke_dashoffset" select="." />
2741     <xsl:apply-templates mode="stroke_linejoin" select="." />
2742     <xsl:apply-templates mode="stroke_linecap" select="." />
2743     <xsl:apply-templates mode="filter_effect" select="." />
2744     <xsl:apply-templates mode="object_opacity" select="." />
2745     <xsl:apply-templates mode="desc" select="." />
2746     <xsl:apply-templates mode="resources" select="." />
2747     <xsl:apply-templates mode="clip" select="." />
2749     <xsl:apply-templates mode="transform" select=".">
2750       <xsl:with-param name="mapped_type" select="'Ellipse'" />
2751     </xsl:apply-templates>
2753     <xsl:apply-templates mode="forward" />
2754   </Ellipse>
2755 </xsl:template>
2757 <!-- 
2758   // Image object//
2759   SVG: image, FXG: Image
2760 -->
2761 <xsl:template mode="forward" match="*[name(.) = 'image']">
2762   <Image>
2763     <xsl:apply-templates mode="id" select="." />
2764     <xsl:if test="@x">
2765       <xsl:attribute name="Canvas.Left">
2766         <xsl:call-template name="convert_unit">
2767           <xsl:with-param name="convert_value" select="@x" />
2768         </xsl:call-template>
2769       </xsl:attribute>
2770     </xsl:if>
2771     <xsl:if test="@y">
2772       <xsl:attribute name="Canvas.Top">
2773         <xsl:call-template name="convert_unit">
2774           <xsl:with-param name="convert_value" select="@y" />
2775         </xsl:call-template>
2776       </xsl:attribute>
2777     </xsl:if>
2778     <xsl:apply-templates mode="desc" select="." />
2779     <xsl:apply-templates mode="clip" select="." />
2780     <xsl:if test="@xlink:href">
2781       <xsl:attribute name="Source">
2782         <xsl:value-of select="@xlink:href" />
2783       </xsl:attribute>
2784     </xsl:if>
2785     <xsl:if test="@width">
2786       <xsl:attribute name="Width">
2787         <xsl:call-template name="convert_unit">
2788           <xsl:with-param name="convert_value" select="@width" />
2789         </xsl:call-template>
2790       </xsl:attribute>
2791     </xsl:if>
2792     <xsl:if test="@height">
2793       <xsl:attribute name="Height">
2794         <xsl:call-template name="convert_unit">
2795           <xsl:with-param name="convert_value" select="@height" />
2796         </xsl:call-template>
2797       </xsl:attribute>
2798     </xsl:if>
2799     
2800     <xsl:apply-templates mode="image_stretch" select="." />
2801     <xsl:apply-templates mode="object_opacity" select="." />
2802     <xsl:apply-templates mode="resources" select="." />
2803     
2804     <xsl:apply-templates mode="transform" select=".">
2805       <xsl:with-param name="mapped_type" select="'Image'" />
2806     </xsl:apply-templates>
2807     <xsl:apply-templates mode="forward" />
2808   </Image>
2809 </xsl:template>
2811 <!--
2812 // Geometry //
2813 * Generic clip path template
2814 * Geometry for path
2815 * Geometry for circle
2816 * Geometry for rectangle
2817 -->
2819 <!-- 
2820   // Generic clip path template //
2821 -->
2822 <xsl:template mode="forward" match="*[name(.) = 'clipPath']">
2823   <xsl:apply-templates mode="geometry" />
2824 </xsl:template>
2826 <!-- 
2827   // Clip Geometry for path //
2828   TODO: PathGeometry is positionned in the object's space, and thus needs to be translated.
2829 -->
2830 <xsl:template mode="geometry" match="*[name(.) = 'path']">
2831   <PathGeometry>
2832     <xsl:if test="../@id">
2833       <xsl:attribute name="x:Key">
2834         <xsl:value-of select="../@id" />
2835       </xsl:attribute>
2836     </xsl:if>
2837     <xsl:attribute name="Figures">
2838       <xsl:value-of select="translate(@d , ',', ' ')" />
2839     </xsl:attribute>
2840     <xsl:apply-templates mode="fill_rule" select="." />
2841     <xsl:apply-templates mode="transform" select=".">
2842       <xsl:with-param name="mapped_type" select="'PathGeometry'" />
2843     </xsl:apply-templates>
2844   </PathGeometry>
2845 </xsl:template>
2847 <!-- 
2848   // Clip Geometry for circle //
2849 -->
2850 <xsl:template mode="geometry" match="*[name(.) = 'circle' or name(.) = 'ellipse']">
2851   <EllipseGeometry>
2852     <xsl:if test="../@id">
2853       <xsl:attribute name="x:Key">
2854         <xsl:value-of select="../@id" />
2855       </xsl:attribute>
2856     </xsl:if>
2857     <xsl:if test="@cx and @cy">
2858       <xsl:attribute name="Center">
2859         <xsl:value-of select="concat(@cx, ',', @cy)" />
2860       </xsl:attribute>
2861     </xsl:if>
2862     <xsl:if test="@r">
2863       <xsl:attribute name="RadiusX">
2864         <xsl:value-of select="@r" />
2865       </xsl:attribute>
2866       <xsl:attribute name="RadiusY">
2867         <xsl:value-of select="@r" />
2868       </xsl:attribute>
2869     </xsl:if>
2870     <xsl:if test="@rx">
2871       <xsl:attribute name="RadiusX">
2872         <xsl:value-of select="@rx" />
2873       </xsl:attribute>
2874     </xsl:if>
2875     <xsl:if test="@ry">
2876       <xsl:attribute name="RadiusY">
2877         <xsl:value-of select="@ry" />
2878       </xsl:attribute>
2879     </xsl:if>
2880     <xsl:apply-templates mode="transform" select=".">
2881       <xsl:with-param name="mapped_type" select="'EllipseGeometry'" />
2882     </xsl:apply-templates>
2883   </EllipseGeometry>
2884 </xsl:template>
2886 <!-- 
2887   // Clip Geometry for rectangle //
2888 -->
2889 <xsl:template mode="geometry" match="*[name(.) = 'rect']">
2890   <RectangleGeometry>
2891     <xsl:if test="../@id">
2892       <xsl:attribute name="x:Key">
2893         <xsl:value-of select="../@id" />
2894       </xsl:attribute>
2895     </xsl:if>
2896     <xsl:variable name="x">
2897         <xsl:call-template name="convert_unit">
2898           <xsl:with-param name="convert_value" select="@x" />
2899         </xsl:call-template>
2900     </xsl:variable>
2901     <xsl:variable name="y">
2902         <xsl:call-template name="convert_unit">
2903           <xsl:with-param name="convert_value" select="@y" />
2904         </xsl:call-template>
2905     </xsl:variable>
2906     <xsl:variable name="width">
2907         <xsl:call-template name="convert_unit">
2908           <xsl:with-param name="convert_value" select="@width" />
2909         </xsl:call-template>
2910     </xsl:variable>
2911     <xsl:variable name="height">
2912       <xsl:call-template name="convert_unit">
2913         <xsl:with-param name="convert_value" select="@height" />
2914       </xsl:call-template>
2915     </xsl:variable>
2916     <xsl:if test="@rx">
2917       <xsl:attribute name="RadiusX">
2918         <xsl:value-of select="@rx" />
2919       </xsl:attribute>
2920     </xsl:if>
2921     <xsl:if test="@ry">
2922       <xsl:attribute name="RadiusY">
2923         <xsl:value-of select="@ry" />
2924       </xsl:attribute>
2925     </xsl:if>
2926     <xsl:if test="@rx and not(@ry)">
2927       <xsl:attribute name="RadiusX">
2928         <xsl:value-of select="@rx" />
2929       </xsl:attribute>
2930       <xsl:attribute name="RadiusY">
2931         <xsl:value-of select="@rx" />
2932       </xsl:attribute>
2933     </xsl:if>
2934     <xsl:if test="@ry and not(@rx)">
2935       <xsl:attribute name="RadiusX">
2936         <xsl:value-of select="@ry" />
2937       </xsl:attribute>
2938       <xsl:attribute name="RadiusY">
2939         <xsl:value-of select="@ry" />
2940       </xsl:attribute>
2941     </xsl:if>
2942     <xsl:attribute name="Rect"><xsl:value-of select="concat($x, ', ', $y, ', ', $width, ', ', $height)" /></xsl:attribute>
2943     <xsl:apply-templates mode="transform" select=".">
2944       <xsl:with-param name="mapped_type" select="'RectangleGeometry'" />
2945     </xsl:apply-templates>
2946   </RectangleGeometry>
2947 </xsl:template>
2949 </xsl:stylesheet>