Code

Extensions. XAML export improvements (gradients, clipping) and minor fixes.
[inkscape.git] / share / extensions / svg2xaml.xsl
index a21da1290938d6232f734d7a9b2c750d54a2c2ec..aabfffbd066d7c4ce4912586e6b1831d7e3121ba 100755 (executable)
@@ -39,7 +39,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 <xsl:strip-space elements="*" />
 <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
 
-<xsl:param name="silverlight_compatible" select="1" />
+<xsl:param name="silverlight_compatible" select="2" />
 
 <!-- 
   // Containers //
@@ -70,9 +70,10 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 -->
 <xsl:template mode="forward" match="*[name(.) = 'svg' or name(.) = 'g']">
   <xsl:choose>
-    <xsl:when test="name(.) = 'svg' or @transform or @viewBox or @id or @clip-path or (@style and contains(@style, 'clip-path:url(#')) or (@width and not(contains(@width, '%'))) or @x or @y or (@height and not(contains(@height, '%'))) or *[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">
+    <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']">
       <Canvas>
         <xsl:apply-templates mode="id" select="." />
+        <xsl:apply-templates mode="filter_effect" select="." />
         <!--
         <xsl:apply-templates mode="clip" select="." />
         -->
@@ -118,6 +119,8 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
             </xsl:call-template>
           </xsl:attribute>
         </xsl:if>
+        <xsl:apply-templates mode="resources" select="." />
+        
         <xsl:if test="@viewBox">
           <xsl:variable name="viewBox">
             <xsl:value-of select="normalize-space(translate(@viewBox, ',', ' '))" />
@@ -140,14 +143,10 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
           </Canvas.RenderTransform>
         </xsl:if>
         <xsl:if test="@transform">
-          <Canvas>
-            <Canvas.RenderTransform>
-              <TransformGroup>
-                <xsl:apply-templates mode="transform" select="." />
-              </TransformGroup>
-            </Canvas.RenderTransform>
+            <xsl:apply-templates mode="transform" select=".">
+              <xsl:with-param name="mapped_type" select="'Canvas'" />
+            </xsl:apply-templates>
             <xsl:apply-templates mode="forward" select="*" />
-          </Canvas>
         </xsl:if>
 
         <xsl:if test="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">
@@ -298,6 +297,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 -->
 <xsl:template mode="transform" match="*">
   <xsl:param name="mapped_type" />
+  
   <xsl:if test="@transform or @gradientTransform">
     <xsl:variable name="transform">
       <xsl:choose>
@@ -309,14 +309,63 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
+
+    <xsl:variable name="values" select="normalize-space(translate($transform, ',', ' '))" />
+    <xsl:variable name="value1">
+      <xsl:choose>
+        <xsl:when test="contains($values, ') ')">
+          <xsl:value-of select="concat(substring-before($values, ') '), ')')" />
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$values" />
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+    <xsl:variable name="value2">
+      <xsl:if test="substring-after($values, $value1) != ''">
+        <xsl:choose>
+          <xsl:when test="contains(substring-after($values, $value1), ') ')">
+            <xsl:value-of select="normalize-space(concat(substring-before(substring-after($values, $value1), ') '), ')'))" />
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="normalize-space(substring-after($values, $value1))" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:if>
+    </xsl:variable>
+    <xsl:variable name="value3">
+      <xsl:if test="$value2 != '' and substring-after($values, $value2) != ''">
+        <xsl:choose>
+          <xsl:when test="contains(substring-after($values, $value2), ') ')">
+            <xsl:value-of select="normalize-space(concat(substring-before(substring-after($values, $value2), ') '), ')'))" />
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="normalize-space(substring-after($values, $value2))" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:if>
+    </xsl:variable>
+
     <xsl:variable name="transform_nodes">
-      <xsl:call-template name="parse_transform">
-        <xsl:with-param name="input" select="$transform" />
-      </xsl:call-template>
+      <xsl:if test="$value3 !=''">
+        <xsl:call-template name="parse_transform">
+          <xsl:with-param name="input" select="$value3" />
+        </xsl:call-template>
+      </xsl:if>
+      <xsl:if test="$value2 !=''">
+        <xsl:call-template name="parse_transform">
+          <xsl:with-param name="input" select="$value2" />
+        </xsl:call-template>
+      </xsl:if>
+      <xsl:if test="$value1 !=''">
+        <xsl:call-template name="parse_transform">
+          <xsl:with-param name="input" select="$value1" />
+        </xsl:call-template>
+      </xsl:if>
     </xsl:variable>
 
     <xsl:choose>
-      <xsl:when test="$mapped_type and $mapped_type != ''">
+      <xsl:when test="$mapped_type and $mapped_type != '' and not(contains($mapped_type, 'Geometry'))">
         <xsl:element name="{$mapped_type}.RenderTransform">
           <xsl:choose>
             <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1">
@@ -330,6 +379,20 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
           </xsl:choose>
         </xsl:element>
       </xsl:when>
+      <xsl:when test="$mapped_type and $mapped_type != '' and contains($mapped_type, 'Geometry')">
+        <xsl:element name="{$mapped_type}.Transform">
+          <xsl:choose>
+            <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1">
+              <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
+            </xsl:when>
+            <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1">
+              <TransformGroup>
+                <xsl:copy-of select="libxslt:node-set($transform_nodes)" />
+              </TransformGroup>
+            </xsl:when>
+          </xsl:choose>
+        </xsl:element>
+      </xsl:when>
       <xsl:otherwise>
         <!-- For instance LinearGradient.Transform -->
         <xsl:choose>
@@ -355,6 +418,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   * Generic filters template
   * Filter effects
   * Linked filter effects
+  * Absolute gradients
   * Linear gradients
   * Radial gradients
   * Generic gradient stops
@@ -366,7 +430,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 -->
 <xsl:template mode="resources" match="*">
   <!-- should be in-depth -->
-  <xsl:if test="ancestor::*[name(.) = 'defs']"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>
+  <xsl:if test="parent::*[name(.) = 'defs']"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>
 </xsl:template>
 
 <!--
@@ -426,14 +490,48 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@filter, 'url(#'), ')'), '}')" />
       </xsl:attribute>
     </xsl:when>
-    <xsl:when test="@style and contains(@style, 'filter:url(#')">
+    <xsl:when test="@style and contains(normalize-space(substring-after(translate(@style, '&quot;', ''), 'filter:')), 'url(#')">
       <xsl:attribute name="Effect">
-        <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'filter:url(#'), ')'), '}')" />
+        <xsl:value-of select="concat('{StaticResource ', substring-before(normalize-space(substring-after(substring-after(translate(@style, '&quot;', ''), 'filter:'), 'url(#')), ')'), '}')" />
       </xsl:attribute>
     </xsl:when>
   </xsl:choose>
 </xsl:template>
 
+<!--
+  // Absolute gradients //
+  Get the calling object position in order to substract it from the absolute gradient position.
+  (XAML absolute gradients values are absolute in the gradient's space).
+-->
+<xsl:template mode="absolute_gradient" match="*">
+  <xsl:param name="position" />
+  <xsl:if test="@id">
+    <xsl:variable name="id" select="concat('#', @id)"/>
+    <xsl:variable name="value">
+      <xsl:for-each select="//*[contains(@style,$id) or contains(@fill,$id) or contains(@stroke,$id)]">
+        <xsl:choose>
+          <xsl:when test="$position = 'y' and @y">
+            <xsl:call-template name="convert_unit">
+              <xsl:with-param name="convert_value" select="@y" />
+            </xsl:call-template>
+          </xsl:when>
+          <xsl:when test="$position = 'x' and @x">
+            <xsl:call-template name="convert_unit">
+              <xsl:with-param name="convert_value" select="@x" />
+            </xsl:call-template>
+          </xsl:when>
+        </xsl:choose>
+      </xsl:for-each>
+    </xsl:variable>
+    <xsl:choose>
+      <xsl:when test="$value != ''">
+        <xsl:value-of select="$value"/>
+      </xsl:when>
+      <xsl:otherwise>0</xsl:otherwise>
+    </xsl:choose>
+  </xsl:if>
+</xsl:template>
+
 <!--
   // Linear gradient //
 -->
@@ -459,6 +557,26 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         </xsl:choose>
       </xsl:attribute>
     </xsl:if>
+    <xsl:variable name="left">
+      <xsl:choose>
+        <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
+          <xsl:apply-templates mode="absolute_gradient" select=".">
+            <xsl:with-param name="position" select="'x'" />
+          </xsl:apply-templates>
+        </xsl:when>
+        <xsl:otherwise>0</xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+    <xsl:variable name="top">
+      <xsl:choose>
+        <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
+          <xsl:apply-templates mode="absolute_gradient" select=".">
+            <xsl:with-param name="position" select="'y'" />
+          </xsl:apply-templates>
+        </xsl:when>
+        <xsl:otherwise>0</xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
     <xsl:choose>
       <xsl:when test="@x1 and @y1 and @x2 and @y2">
         <xsl:choose>
@@ -469,7 +587,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
           </xsl:when>
           <xsl:otherwise>
             <xsl:attribute name="StartPoint">
-              <xsl:value-of select="concat(@x1, ',', @y1)" />
+              <xsl:value-of select="concat((@x1 - $left), ',', (@y1 - $top))" />
             </xsl:attribute>
           </xsl:otherwise>
         </xsl:choose>
@@ -481,7 +599,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
           </xsl:when>
           <xsl:otherwise>
             <xsl:attribute name="EndPoint">
-              <xsl:value-of select="concat(@x2, ',', @y2)" />
+              <xsl:value-of select="concat((@x2 - $left), ',', (@y2 - $top))" />
             </xsl:attribute>
           </xsl:otherwise>
         </xsl:choose>  
@@ -541,6 +659,26 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         </xsl:choose>
       </xsl:attribute>
     </xsl:if>
+    <xsl:variable name="left">
+      <xsl:choose>
+        <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
+          <xsl:apply-templates mode="absolute_gradient" select=".">
+            <xsl:with-param name="position" select="'x'" />
+          </xsl:apply-templates>
+        </xsl:when>
+        <xsl:otherwise>0</xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+    <xsl:variable name="top">
+      <xsl:choose>
+        <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">
+          <xsl:apply-templates mode="absolute_gradient" select=".">
+            <xsl:with-param name="position" select="'y'" />
+          </xsl:apply-templates>
+        </xsl:when>
+        <xsl:otherwise>0</xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
     <xsl:if test="@cx and @cy">
       <xsl:attribute name="Center">
         <xsl:choose>
@@ -548,7 +686,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
             <xsl:value-of select="concat(number(substring-before(@cx, '%')) div 100, ',', number(substring-before(@cy, '%')) div 100)" />
           </xsl:when>
           <xsl:otherwise>
-            <xsl:value-of select="concat(@cx, ',', @cy)" />
+            <xsl:value-of select="concat((@cx - $left), ',', (@cy - $top))" />
           </xsl:otherwise>
         </xsl:choose>
       </xsl:attribute>
@@ -560,7 +698,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
             <xsl:value-of select="concat(number(substring-before(@fx, '%')) div 100, ',', number(substring-before(@fy, '%')) div 100)" />
           </xsl:when>
           <xsl:otherwise>
-            <xsl:value-of select="concat(@fx, ',', @fy)" />
+            <xsl:value-of select="concat((@fx - $left), ',', (@fy - $top))" />
           </xsl:otherwise>
         </xsl:choose>
       </xsl:attribute>
@@ -590,7 +728,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         <xsl:choose>
           <xsl:when test="@xlink:href">
             <xsl:variable name="reference_id" select="@xlink:href" />
-            <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />
+            <xsl:apply-templates mode="forward" select="//*[name(.) = 'radialGradient' and $reference_id = concat('#', @id)]/*" />
           </xsl:when>
           <xsl:otherwise>
             <xsl:apply-templates mode="forward" />
@@ -767,15 +905,46 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   (since it is not supported by Inkscape, not implemented yet)
 -->
 <xsl:template mode="forward" match="*[name(.) = 'use']">
+<!-- Errors when more than one use element share the same reference
   <Canvas>
-    <xsl:if test="@xlink:href">
-      <xsl:attribute name="Style">
-        <xsl:value-of select="@xlink:href" />
+    <xsl:if test="@width and not(contains(@width, '%'))">
+      <xsl:attribute name="Width">
+        <xsl:call-template name="convert_unit">
+          <xsl:with-param name="convert_value" select="@width" />
+        </xsl:call-template>
       </xsl:attribute>
     </xsl:if>
-    <!--xsl:apply-templates mode="transform" select="." /-->
-    <xsl:apply-templates mode="forward" />
+      <xsl:if test="@height and not(contains(@height, '%'))">
+      <xsl:attribute name="Height">
+        <xsl:call-template name="convert_unit">
+          <xsl:with-param name="convert_value" select="@height" />
+        </xsl:call-template>
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@x">
+      <xsl:attribute name="Canvas.Left">
+        <xsl:call-template name="convert_unit">
+          <xsl:with-param name="convert_value" select="@x" />
+        </xsl:call-template>
+      </xsl:attribute></xsl:if>
+    <xsl:if test="@y">
+      <xsl:attribute name="Canvas.Top">
+        <xsl:call-template name="convert_unit">
+          <xsl:with-param name="convert_value" select="@y" />
+        </xsl:call-template>
+      </xsl:attribute>
+    </xsl:if>
+    
+    <StaticResource>
+      <xsl:if test="@xlink:href">
+        <xsl:attribute name="ResourceKey">
+          <xsl:value-of select="substring-after(@xlink:href, '#')" />
+        </xsl:attribute>
+      </xsl:if>
+      <xsl:apply-templates mode="forward" />
+    </StaticResource>
   </Canvas>
+  -->
 </xsl:template>
 
 <!--
@@ -812,6 +981,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 // Colors and patterns //
 
 * Generic color template
+* Object opacity
 * Fill
 * Fill opacity
 * Fill rule
@@ -830,6 +1000,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 * Gradient stop
 * Gradient stop opacity
 * Gradient stop offset
+* Image stretch
 -->
 
 <!--
@@ -934,23 +1105,74 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   </xsl:choose>
 </xsl:template>
 
+<!--
+  // Object opacity //
+-->
+<xsl:template mode="object_opacity" match="*">
+  <xsl:if test="@opacity or (@style and (contains(@style, ';opacity:') or starts-with(@style, 'opacity:')))">
+    <xsl:variable name="value">
+    <xsl:choose>
+      <xsl:when test="@opacity">
+        <xsl:value-of select="@opacity" />
+      </xsl:when>
+      <xsl:when test="@style and contains(@style, ';opacity:')">
+        <xsl:variable name="Opacity" select="substring-after(@style, ';opacity:')" />
+        <xsl:choose>
+          <xsl:when test="contains($Opacity, ';')">
+            <xsl:value-of select="substring-before($Opacity, ';')" />
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$Opacity" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:when>
+      <xsl:when test="@style and starts-with(@style, 'opacity:')">
+        <xsl:variable name="Opacity" select="substring-after(@style, 'opacity:')" />
+        <xsl:choose>
+          <xsl:when test="contains($Opacity, ';')">
+            <xsl:value-of select="substring-before($Opacity, ';')" />
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$Opacity" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:when>
+      <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
+        <xsl:apply-templates mode="object_opacity" select="parent::*" />
+      </xsl:when>
+      <xsl:otherwise>1</xsl:otherwise>
+    </xsl:choose>
+    </xsl:variable>
+    <xsl:attribute name="Opacity">
+    <xsl:choose>
+      <xsl:when test="$value &lt; 0">0</xsl:when>
+      <xsl:when test="$value &gt; 1">1</xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$value" />
+      </xsl:otherwise>
+    </xsl:choose>
+    </xsl:attribute>
+  </xsl:if>
+</xsl:template>
+
 <!--
   // Fill //
 -->
 <xsl:template mode="fill" match="*">
   <xsl:variable name="value">
     <xsl:choose>
-      <xsl:when test="@fill and starts-with(@fill, 'url(#')">
-        <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@fill, 'url(#'), ')'), '}')" />
+      <xsl:when test="@fill and starts-with(normalize-space(translate(@fill, '&quot;', '')), 'url(#')">
+        <!-- Removes unwanted characters in the color link (TODO: export to a specific template)-->
+        <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(normalize-space(translate(@fill, '&quot;', '')), 'url(#'), ')'), '}')" />
       </xsl:when>
       <xsl:when test="@fill">
-        <xsl:value-of select="@fill" />
+        <xsl:value-of select="normalize-space(@fill)" />
       </xsl:when>
-      <xsl:when test="@style and contains(@style, 'fill:') and starts-with(substring-after(@style, 'fill:'), 'url(#')">
-        <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" />
+      <xsl:when test="@style and contains(@style, 'fill:') and starts-with(normalize-space(substring-after(translate(@style, '&quot;', ''), 'fill:')), 'url(#')">
+        <xsl:value-of select="concat('{StaticResource ', substring-before(normalize-space(substring-after(substring-after(translate(@style, '&quot;', ''), 'fill:'), 'url(#')), ')'), '}')" />
       </xsl:when>
       <xsl:when test="@style and contains(@style, 'fill:')">
-        <xsl:variable name="Fill" select="substring-after(@style, 'fill:')" />
+        <xsl:variable name="Fill" select="normalize-space(substring-after(@style, 'fill:'))" />
         <xsl:choose>
           <xsl:when test="contains($Fill, ';')">
             <xsl:value-of select="substring-before($Fill, ';')" />
@@ -966,8 +1188,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     </xsl:choose>
   </xsl:variable>
   <xsl:if test="$value">
-    <!-- Removes unwanted characters in the color link (TODO: export to a specific template)-->
-    <xsl:value-of select="normalize-space(translate($value, '&quot;', ''))" />
+    <xsl:value-of select="$value" />
   </xsl:if>
 </xsl:template>
 
@@ -978,10 +1199,10 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   <xsl:variable name="value">
   <xsl:choose>
     <xsl:when test="@fill-opacity">
-      <xsl:value-of select="@fill-opacity" />
+      <xsl:value-of select="normalize-space(@fill-opacity)" />
     </xsl:when>
     <xsl:when test="@style and contains(@style, 'fill-opacity:')">
-      <xsl:variable name="Opacity" select="substring-after(@style, 'fill-opacity:')" />
+      <xsl:variable name="Opacity" select="normalize-space(substring-after(@style, 'fill-opacity:'))" />
       <xsl:choose>
         <xsl:when test="contains($Opacity, ';')">
           <xsl:value-of select="substring-before($Opacity, ';')" />
@@ -1013,7 +1234,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   <xsl:choose>
     <xsl:when test="@fill-rule and (@fill-rule = 'nonzero' or @fill-rule = 'evenodd')">
       <xsl:attribute name="FillRule">
-        <xsl:value-of select="@fill-rule" />
+        <xsl:value-of select="normalize-space(@fill-rule)" />
       </xsl:attribute>
     </xsl:when>
     <xsl:when test="@style and contains(@style, 'fill-rule:')">
@@ -1075,16 +1296,17 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 <xsl:template mode="stroke" match="*">
   <xsl:choose>
     <xsl:when test="@stroke and starts-with(@stroke, 'url(#')">
-      <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@stroke, 'url(#'), ')'), '}')" />
+      <!-- Removes unwanted characters in the color link (TODO: export to a specific template)-->
+      <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(normalize-space(translate(@stroke, '&quot;', '')), 'url(#'), ')'), '}')" />
     </xsl:when>
-    <xsl:when test="@stroke and @stroke != 'none'">
+    <xsl:when test="@stroke and normalize-space(@stroke) != 'none'">
       <xsl:value-of select="@stroke" />
     </xsl:when>
-    <xsl:when test="@style and contains(@style, 'stroke:') and starts-with(substring-after(@style, 'stroke:'), 'url(#')">
-      <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" />
+    <xsl:when test="@style and contains(@style, 'stroke:') and starts-with(normalize-space(substring-after(translate(@style, '&quot;', ''), 'stroke:')), 'url(#')">
+      <xsl:value-of select="concat('{StaticResource ', substring-before(normalize-space(substring-after(substring-after(translate(@style, '&quot;', ''), 'stroke:'), 'url(#')), ')'), '}')" />
     </xsl:when>
     <xsl:when test="@style and contains(@style, 'stroke:')">
-      <xsl:variable name="Stroke" select="substring-after(@style, 'stroke:')" />
+      <xsl:variable name="Stroke" select="normalize-space(substring-after(@style, 'stroke:'))" />
       <xsl:choose>
         <xsl:when test="contains($Stroke, ';')">
           <xsl:if test="substring-before($Stroke, ';') != 'none'">
@@ -1209,11 +1431,11 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   <xsl:choose>
     <xsl:when test="@stroke-miterlimit">
       <xsl:attribute name="StrokeMiterLimit">
-        <xsl:value-of select="@stroke-miterlimit" />
+        <xsl:value-of select="normalize-space(@stroke-miterlimit)" />
       </xsl:attribute>
     </xsl:when>
     <xsl:when test="@style and contains(@style, 'stroke-miterlimit:')">
-      <xsl:variable name="StrokeMiterLimit" select="substring-after(@style, 'stroke-miterlimit:')" />
+      <xsl:variable name="StrokeMiterLimit" select="normalize-space(substring-after(@style, 'stroke-miterlimit:'))" />
       <xsl:attribute name="StrokeMiterLimit">
         <xsl:choose>
           <xsl:when test="contains($StrokeMiterLimit, ';')">
@@ -1237,7 +1459,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 <xsl:template mode="stroke_dasharray" match="*">
   <!-- stroke-dasharray="10,30,20,30" becomes StrokeDashArray="1 3 2 3" ?? -->
   <xsl:choose>
-    <xsl:when test="@stroke-dasharray and @stroke-dasharray != 'none'">
+    <xsl:when test="@stroke-dasharray and normalize-space(@stroke-dasharray) != 'none'">
       <xsl:attribute name="StrokeDashArray">
         <xsl:value-of select="@stroke-dasharray" />
       </xsl:attribute>
@@ -1246,13 +1468,13 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
       <xsl:variable name="StrokeDashArray" select="substring-after(@style, 'stroke-dasharray:')" />
       <xsl:choose>
         <xsl:when test="contains($StrokeDashArray, ';')">
-          <xsl:if test="substring-before($StrokeDashArray, ';') != 'none'">
+          <xsl:if test="normalize-space(substring-before($StrokeDashArray, ';')) != 'none'">
             <xsl:attribute name="StrokeDashArray">
               <xsl:value-of select="substring-before($StrokeDashArray, ';')" />
             </xsl:attribute>
           </xsl:if>
         </xsl:when>
-        <xsl:when test="$StrokeDashArray != 'none'">
+        <xsl:when test="normalize-space($StrokeDashArray) != 'none'">
           <xsl:attribute name="StrokeDashArray">
             <xsl:value-of select="$StrokeDashArray" />
           </xsl:attribute>
@@ -1270,23 +1492,38 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 -->
 <xsl:template mode="stroke_dashoffset" match="*">
   <xsl:choose>
-    <xsl:when test="@stroke-dashoffset">
-      <xsl:attribute name="StrokeDashOffset">
-        <xsl:value-of select="@stroke-dashoffset" />
-      </xsl:attribute>
-    </xsl:when>
-    <xsl:when test="@style and contains(@style, 'stroke-dashoffset:')">
-      <xsl:variable name="StrokeDashOffset" select="substring-after(@style, 'stroke-dashoffset:')" />
-      <xsl:attribute name="StrokeDashOffset">
+    <xsl:when test="@stroke-dashoffset or (@style and contains(@style, 'stroke-dashoffset:'))">
+      <xsl:variable name="value">
         <xsl:choose>
-          <xsl:when test="contains($StrokeDashOffset, ';')">
-            <xsl:value-of select="substring-before($StrokeDashOffset, ';')" />
+          <xsl:when test="@stroke-dashoffset">
+            <xsl:call-template name="convert_unit">
+              <xsl:with-param name="convert_value" select="normalize-space(@stroke-dashoffset)" />
+            </xsl:call-template>
+          </xsl:when>
+          <xsl:when test="@style and contains(@style, 'stroke-dashoffset:')">
+            <xsl:variable name="StrokeDashOffset" select="normalize-space(substring-after(@style, 'stroke-dashoffset:'))" />
+            <xsl:attribute name="StrokeDashOffset">
+              <xsl:choose>
+                <xsl:when test="contains($StrokeDashOffset, ';')">
+                  <xsl:call-template name="convert_unit">
+                    <xsl:with-param name="convert_value" select="substring-before($StrokeDashOffset, ';')" />
+                  </xsl:call-template>
+                </xsl:when>
+                <xsl:otherwise>
+                  <xsl:call-template name="convert_unit">
+                    <xsl:with-param name="convert_value" select="$StrokeDashOffset" />
+                  </xsl:call-template>
+                </xsl:otherwise>
+              </xsl:choose>
+            </xsl:attribute>
           </xsl:when>
-          <xsl:otherwise>
-            <xsl:value-of select="$StrokeDashOffset" />
-          </xsl:otherwise>
         </xsl:choose>
-      </xsl:attribute>
+      </xsl:variable>
+      <xsl:if test="value != ''">
+        <xsl:attribute name="StrokeDashOffset">
+          <xsl:value-of select="$value" />
+        </xsl:attribute>
+      </xsl:if>
     </xsl:when>
     <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
       <xsl:apply-templates mode="stroke_dashoffset" select="parent::*"/>
@@ -1311,7 +1548,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 -->
 <xsl:template mode="stroke_linejoin" match="*">
   <xsl:choose>
-    <xsl:when test="@stroke-miterlimit">
+    <xsl:when test="@stroke-linejoin">
       <xsl:attribute name="StrokeLineJoin">
         <xsl:call-template name="linejoin_svg_to_xaml">
           <xsl:with-param name="linejoin">
@@ -1433,10 +1670,10 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   <xsl:variable name="Opacity">
     <xsl:choose>
       <xsl:when test="@stop-opacity">
-        <xsl:value-of select="@stop-opacity" />
+        <xsl:value-of select="normalize-space(@stop-opacity)" />
       </xsl:when>
       <xsl:when test="@style and contains(@style, 'stop-opacity:')">
-        <xsl:variable name="temp_opacity" select="substring-after(@style, 'stop-opacity:')" />
+        <xsl:variable name="temp_opacity" select="normalize-space(substring-after(@style, 'stop-opacity:'))" />
         <xsl:choose>
           <xsl:when test="contains($temp_opacity, ';')">
             <xsl:value-of select="substring-before($temp_opacity, ';')" />
@@ -1470,12 +1707,12 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
       <xsl:when test="@stop-color">
         <xsl:call-template name="template_color">
           <xsl:with-param name="colorspec">
-            <xsl:value-of select="@stop-color" />
+            <xsl:value-of select="normalize-space(@stop-color)" />
           </xsl:with-param>
         </xsl:call-template>
       </xsl:when>
       <xsl:when test="@style and contains(@style, 'stop-color:')">
-        <xsl:variable name="Color" select="substring-after(@style, 'stop-color:')" />
+        <xsl:variable name="Color" select="normalize-space(substring-after(@style, 'stop-color:'))" />
         <xsl:choose>
           <xsl:when test="contains($Color, ';')">
             <xsl:call-template name="template_color">
@@ -1496,7 +1733,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
       <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
         <xsl:apply-templates mode="stop_color" select="parent::*"/>
       </xsl:when>
-      <xsl:otherwise>#000</xsl:otherwise>
+      <xsl:otherwise>#000000</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <xsl:attribute name="Color">
@@ -1579,6 +1816,34 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   </xsl:choose>
 </xsl:template>
 
+<!-- 
+  // Image stretch //
+  SVG: preserveAspectRatio, XAML: Stretch
+-->
+<xsl:template mode="image_stretch" match="*">
+  <xsl:variable name="value">
+    <xsl:choose>
+      <xsl:when test="@preserveAspectRatio">
+        <xsl:value-of select="@preserveAspectRatio" />
+      </xsl:when>
+      <xsl:when test="@style and contains(@style, 'preserveAspectRatio:')">
+        <xsl:variable name="ratio" select="normalize-space(substring-after(@style, 'preserveAspectRatio:'))" />
+        <xsl:choose>
+          <xsl:when test="contains($ratio, ';')">
+            <xsl:value-of select="substring-before($ratio, ';')" />
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$ratio" />
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:when>
+    </xsl:choose>
+  </xsl:variable>
+  <xsl:if test="$value = 'none'">  
+    <xsl:attribute name="Stretch">Fill</xsl:attribute>
+  </xsl:if>
+</xsl:template>
+
 <!-- 
   // Text specific templates //
 
@@ -1604,33 +1869,27 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 
  <!-- 
   // Text span //
-  SVG: tspan, flowSpan, FXG: span
+  SVG: tspan, flowSpan, XAML: Span
   
-  Not supported in FXG:
+  Not supported in XAML:
   * span position
 -->
 <xsl:template mode="forward" match="*[name(.) = 'tspan'  or name(.) = 'flowSpan']">
-  <span>
+  <Span>
     <xsl:if test="../@xml:space='preserve'">
       <xsl:attribute name="whiteSpaceCollapse">preserve</xsl:attribute>
     </xsl:if>
     <xsl:variable name="fill">
       <xsl:apply-templates mode="fill" select="." />
     </xsl:variable>
-    <xsl:variable name="fill_opacity">
-      <xsl:apply-templates mode="fill_opacity" select="." />
-    </xsl:variable>
     <xsl:if test="starts-with($fill, '#') or (not(starts-with($fill, 'url')) and $fill != '' and $fill != 'none')">
-      <xsl:attribute name="color">
+      <xsl:attribute name="Foreground">
         <xsl:call-template name="template_color">
           <xsl:with-param name="colorspec">
             <xsl:value-of select="$fill" />
           </xsl:with-param>
         </xsl:call-template>
       </xsl:attribute>
-      <xsl:attribute name="textAlpha">
-        <xsl:value-of select="$fill_opacity" />
-      </xsl:attribute>
     </xsl:if>
     <xsl:apply-templates mode="font_size" select="." />
     <xsl:apply-templates mode="font_weight" select="." />
@@ -1644,64 +1903,30 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:if test="text()">
       <xsl:value-of select="text()" />
     </xsl:if>
-  </span>
+  </Span>
 </xsl:template>
 
  <!-- 
   // Text flowPara //
-  SVG: flowPara, flowDiv FXG: p
+  SVG: flowPara, flowDiv XAML: ?
   
-  Not supported in FXG:
-  * paragraph position
 -->
 <xsl:template mode="forward" match="*[name(.) = 'flowPara' or name(.) = 'flowDiv']">
-  <p>
-    <xsl:if test="../@xml:space='preserve'">
-      <xsl:attribute name="whiteSpaceCollapse">preserve</xsl:attribute>
-    </xsl:if>
-    <xsl:variable name="fill">
-      <xsl:apply-templates mode="fill" select="." />
-    </xsl:variable>
-    <xsl:variable name="fill_opacity">
-      <xsl:apply-templates mode="fill_opacity" select="." />
-    </xsl:variable>
-    <xsl:if test="starts-with($fill, '#') or (not(starts-with($fill, 'url')) and $fill != '' and $fill != 'none')">
-      <xsl:attribute name="color">
-        <xsl:call-template name="template_color">
-          <xsl:with-param name="colorspec">
-            <xsl:value-of select="$fill" />
-          </xsl:with-param>
-        </xsl:call-template>
-      </xsl:attribute>
-      <xsl:attribute name="textAlpha">
-        <xsl:value-of select="$fill_opacity" />
-      </xsl:attribute>
-    </xsl:if>
-    <xsl:apply-templates mode="font_size" select="." />
-    <xsl:apply-templates mode="font_weight" select="." />
-    <xsl:apply-templates mode="font_family" select="." />
-    <xsl:apply-templates mode="font_style" select="." />
-    <xsl:apply-templates mode="text_fill" select="." />
-    <xsl:apply-templates mode="text_decoration" select="." />
-    <xsl:apply-templates mode="line_height" select="." />
-    <xsl:apply-templates mode="baseline_shift" select="." />
-
-    <xsl:choose>
-      <xsl:when test="*[name(.) = 'flowSpan']/text()">
-        <xsl:apply-templates mode="forward" />
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:choose>
-          <xsl:when test="@xml:space='preserve'">
-            <xsl:copy-of select="translate(text(), '&#x9;&#xA;&#xD;', ' ')" />
-          </xsl:when>
-          <xsl:otherwise>
-            <xsl:copy-of select="normalize-space(translate(text(), '&#x9;&#xA;&#xD;', ' '))" />
-          </xsl:otherwise>
-        </xsl:choose>  
-      </xsl:otherwise>
-    </xsl:choose>
-  </p>
+  <xsl:choose>
+    <xsl:when test="*[name(.) = 'flowSpan']/text()">
+      <xsl:apply-templates mode="forward" />
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:choose>
+        <xsl:when test="@xml:space='preserve'">
+          <xsl:copy-of select="translate(text(), '&#x9;&#xA;&#xD;', ' ')" />
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:copy-of select="normalize-space(translate(text(), '&#x9;&#xA;&#xD;', ' '))" />
+        </xsl:otherwise>
+      </xsl:choose>  
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 
@@ -1732,11 +1957,12 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         </xsl:otherwise>
       </xsl:choose>
     </xsl:when>
-    <xsl:when test="name(..) = 'g' or name(..) = 'svg'">
+    <xsl:when test="name(..) = 'g' or name(..) = 'svg' or name(..) = 'text' or name(..) = 'flowPara' or name(..) = 'flowRoot'">
       <xsl:apply-templates mode="get_font_size" select="parent::*"/>
     </xsl:when>
   </xsl:choose>
 </xsl:template>
+
 <!-- 
   // Text font size //
   SVG: font-size, XAML: FontSize
@@ -1867,7 +2093,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 
 <!-- 
   // Text baseline shift //
-  SVG: baseline-shift, FXG: baselineShift
+  SVG: baseline-shift, XAML: BaselineAlignment
 -->
 <xsl:template mode="baseline_shift" match="*">
   <xsl:variable name="value">
@@ -1881,17 +2107,12 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
       <xsl:value-of select="substring-before(substring-after(@style, 'baseline-shift:'), ';')" />
     </xsl:if>   
   </xsl:variable>
-  <xsl:if test="$value != ''">
-    <xsl:attribute name="baselineShift">  
+  <xsl:if test="$value = 'baseline' or $value='super' or $value='sub'">
+    <xsl:attribute name="BaselineAlignment">  
       <xsl:choose>
-        <xsl:when test="$value='baseline'">0</xsl:when>
-        <xsl:when test="$value='super'">superscript</xsl:when>
-        <xsl:when test="$value='sub'">subscript</xsl:when>
-        <xsl:when test="translate($value, '%', '') &lt; -1000">-1000</xsl:when>
-        <xsl:when test="translate($value, '%', '') &gt; 1000">1000</xsl:when>
-        <xsl:otherwise>
-          <xsl:value-of select="translate($value, '%', '')" />
-        </xsl:otherwise>
+        <xsl:when test="$value='baseline'">Normal</xsl:when>
+        <xsl:when test="$value='super'">Superscript</xsl:when>
+        <xsl:when test="$value='sub'">Subscript</xsl:when>
       </xsl:choose>  
       <xsl:if test="contains($value, '%')">%</xsl:if>
     </xsl:attribute>
@@ -1961,7 +2182,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   
 <!-- 
   // Text decoration //
-  SVG: text-decoration, FXG: textDecoration, lineThrough 
+  SVG: text-decoration, XAML: TextDecorations 
 -->
 <xsl:template mode="text_decoration" match="*">
   <xsl:variable name="value">
@@ -1975,15 +2196,15 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
       <xsl:value-of select="substring-before(substring-after(@style, 'text-decoration:'), ';')" />
     </xsl:if>   
   </xsl:variable>
-  <xsl:if test="$value != ''">  
-    <xsl:choose>
-      <xsl:when test="$value='underline'">
-        <xsl:attribute name="textDecoration">underline</xsl:attribute>
-      </xsl:when>
-      <xsl:when test="$value='line-through'">
-        <xsl:attribute name="lineThrough">true</xsl:attribute>
-      </xsl:when>
-    </xsl:choose>  
+  <xsl:if test="$value != ''">
+    <xsl:attribute name="TextDecorations">
+      <xsl:choose>
+        <xsl:when test="$value='underline'">Underline</xsl:when>
+        <xsl:when test="$value='line-through'">Strikethrough</xsl:when>
+        <xsl:when test="$value='overline'">Overline</xsl:when>
+        <xsl:otherwise>None</xsl:otherwise>
+      </xsl:choose>  
+    </xsl:attribute>
   </xsl:if>
 </xsl:template>
 
@@ -2019,7 +2240,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 
 <!-- 
   // Text direction //
-  SVG: direction, unicode-bidi, FXG: direction
+  SVG: direction, unicode-bidi, XAML: FlowDirection
 -->
 <xsl:template mode="direction" match="*">
   <xsl:variable name="value">
@@ -2046,10 +2267,10 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   </xsl:variable>
 
   <xsl:if test="$value != '' and ($bidi='embed' or $bidi='bidi-override')">  
-    <xsl:attribute name="direction">
+    <xsl:attribute name="FlowDirection">
       <xsl:choose>
-        <xsl:when test="$value='ltr'">ltr</xsl:when>
-        <xsl:when test="$value='rtl'">rtl</xsl:when>
+        <xsl:when test="$value='ltr'">LeftToRight</xsl:when>
+        <xsl:when test="$value='rtl'">RightToLeft</xsl:when>
       </xsl:choose>  
     </xsl:attribute>
   </xsl:if>
@@ -2151,7 +2372,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
   // Text objects //
   SVG: text, XAML: TextBlock
 -->
-<xsl:template mode="forward" match="*[name(.) = 'text']">
+<xsl:template mode="forward" match="*[name(.) = 'text' or name(.) = 'flowRoot']">
   <TextBlock>
     <xsl:apply-templates mode="font_size" select="." />
     <xsl:apply-templates mode="font_weight" select="." />
@@ -2159,7 +2380,14 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="font_style" select="." />
     <xsl:apply-templates mode="text_fill" select="." />
     <xsl:apply-templates mode="text_size" select="." />
+    <xsl:apply-templates mode="text_decoration" select="." />
+    <xsl:apply-templates mode="direction" select="." />
     <xsl:apply-templates mode="text_position" select="." />
+    <xsl:if test="name(.) = 'flowRoot'">
+      <xsl:attribute name="TextWrapping">
+        <xsl:value-of select="'Wrap'" />
+      </xsl:attribute>
+    </xsl:if>
     
     <xsl:if test="@text-anchor">
       <xsl:attribute name="HorizontalAlignment">
@@ -2171,15 +2399,21 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
       </xsl:attribute>
     </xsl:if>
     
+    <xsl:apply-templates mode="object_opacity" select="." />
+    
     <xsl:apply-templates mode="id" select="." />
+    <xsl:if test="name(.) = 'flowRoot'">
+      <xsl:apply-templates mode="flow_region" select="*[name(.) = 'flowRegion']/child::node()" />
+    </xsl:if>
     <xsl:apply-templates mode="filter_effect" select="." />
     <xsl:apply-templates mode="desc" select="." />
+    <xsl:apply-templates mode="resources" select="." />
     <xsl:apply-templates mode="clip" select="." />
     <!--xsl:apply-templates mode="transform" select="." /-->
     <!--xsl:apply-templates mode="forward" /-->
     
     <xsl:choose>
-      <xsl:when test="*[name(.) = 'tspan']/text()">
+      <xsl:when test="*[name(.) = 'tspan' or name(.) = 'flowPara' or name(.) = 'flowDiv']/text()">
         <xsl:apply-templates mode="forward" />
       </xsl:when>
       <xsl:otherwise>
@@ -2223,6 +2457,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         <xsl:value-of select="@y2" />
       </xsl:attribute>
     </xsl:if>
+    
     <xsl:apply-templates mode="id" select="." />
     <xsl:apply-templates mode="template_fill" select="." />
     <xsl:apply-templates mode="template_stroke" select="." />
@@ -2232,7 +2467,9 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="stroke_linejoin" select="." />
     <xsl:apply-templates mode="stroke_linecap" select="." />
     <xsl:apply-templates mode="filter_effect" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
     <xsl:apply-templates mode="desc" select="." />
+    <xsl:apply-templates mode="resources" select="." />
 
     <xsl:apply-templates mode="transform" select=".">
       <xsl:with-param name="mapped_type" select="'Line'" />
@@ -2306,6 +2543,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="stroke_linecap" select="." />
     <xsl:apply-templates mode="filter_effect" select="." />
     <xsl:apply-templates mode="resources" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
     <xsl:apply-templates mode="desc" select="." />
     <xsl:apply-templates mode="clip" select="." />
 
@@ -2334,7 +2572,9 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="stroke_linejoin" select="." />
     <xsl:apply-templates mode="stroke_linecap" select="." />
     <xsl:apply-templates mode="filter_effect" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
     <xsl:apply-templates mode="desc" select="." />
+    <xsl:apply-templates mode="resources" select="." />
 
     <xsl:apply-templates mode="transform" select=".">
       <xsl:with-param name="mapped_type" select="'Polygon'" />
@@ -2361,6 +2601,7 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="stroke_linejoin" select="." />
     <xsl:apply-templates mode="stroke_linecap" select="." />
     <xsl:apply-templates mode="filter_effect" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
     <xsl:apply-templates mode="desc" select="." />
 
     <xsl:apply-templates mode="transform" select=".">
@@ -2386,13 +2627,16 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="stroke_linejoin" select="." />
     <xsl:apply-templates mode="stroke_linecap" select="." />
     <xsl:apply-templates mode="filter_effect" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
     <xsl:apply-templates mode="desc" select="." />
-
+    <xsl:apply-templates mode="resources" select="." />
+    <xsl:apply-templates mode="clip" select="." />
+    
     <xsl:if test="@d">
       <xsl:choose>
         <xsl:when test="$silverlight_compatible = 1">
           <xsl:attribute name="Data">
-           <xsl:value-of select="translate(@d , ',', ' ')" />
+            <xsl:value-of select="translate(@d , ',', ' ')" />
           </xsl:attribute>
         </xsl:when>
         <xsl:otherwise>
@@ -2451,7 +2695,9 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="stroke_linejoin" select="." />
     <xsl:apply-templates mode="stroke_linecap" select="." />
     <xsl:apply-templates mode="filter_effect" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
     <xsl:apply-templates mode="desc" select="." />
+    <xsl:apply-templates mode="resources" select="." />
     <xsl:apply-templates mode="clip" select="." />
 
     <xsl:apply-templates mode="transform" select=".">
@@ -2495,7 +2741,9 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
     <xsl:apply-templates mode="stroke_linejoin" select="." />
     <xsl:apply-templates mode="stroke_linecap" select="." />
     <xsl:apply-templates mode="filter_effect" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
     <xsl:apply-templates mode="desc" select="." />
+    <xsl:apply-templates mode="resources" select="." />
     <xsl:apply-templates mode="clip" select="." />
 
     <xsl:apply-templates mode="transform" select=".">
@@ -2548,6 +2796,11 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
         </xsl:call-template>
       </xsl:attribute>
     </xsl:if>
+    
+    <xsl:apply-templates mode="image_stretch" select="." />
+    <xsl:apply-templates mode="object_opacity" select="." />
+    <xsl:apply-templates mode="resources" select="." />
+    
     <xsl:apply-templates mode="transform" select=".">
       <xsl:with-param name="mapped_type" select="'Image'" />
     </xsl:apply-templates>
@@ -2558,40 +2811,138 @@ exclude-result-prefixes="rdf xlink xs exsl libxslt">
 <!--
 // Geometry //
 * Generic clip path template
+* Geometry for path
 * Geometry for circle
 * Geometry for rectangle
 -->
 
-<!-- Generic clip path template -->
+<!-- 
+  // Generic clip path template //
+-->
 <xsl:template mode="forward" match="*[name(.) = 'clipPath']">
   <xsl:apply-templates mode="geometry" />
 </xsl:template>
 
-<!-- Geometry for circle -->
-<xsl:template mode="geometry" match="*[name(.) = 'circle']">
+<!-- 
+  // Clip Geometry for path //
+  TODO: PathGeometry is positionned in the object's space, and thus needs to be translated.
+-->
+<xsl:template mode="geometry" match="*[name(.) = 'path']">
+  <PathGeometry>
+    <xsl:if test="../@id">
+      <xsl:attribute name="x:Key">
+        <xsl:value-of select="../@id" />
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:attribute name="Figures">
+      <xsl:value-of select="translate(@d , ',', ' ')" />
+    </xsl:attribute>
+    <xsl:apply-templates mode="fill_rule" select="." />
+    <xsl:apply-templates mode="transform" select=".">
+      <xsl:with-param name="mapped_type" select="'PathGeometry'" />
+    </xsl:apply-templates>
+  </PathGeometry>
+</xsl:template>
+
+<!-- 
+  // Clip Geometry for circle //
+-->
+<xsl:template mode="geometry" match="*[name(.) = 'circle' or name(.) = 'ellipse']">
   <EllipseGeometry>
-    <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>
-    <xsl:if test="@cx and @cy"><xsl:attribute name="Center"><xsl:value-of select="concat(@cx, ',', @cy)" /></xsl:attribute></xsl:if>
+    <xsl:if test="../@id">
+      <xsl:attribute name="x:Key">
+        <xsl:value-of select="../@id" />
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@cx and @cy">
+      <xsl:attribute name="Center">
+        <xsl:value-of select="concat(@cx, ',', @cy)" />
+      </xsl:attribute>
+    </xsl:if>
     <xsl:if test="@r">
-      <xsl:attribute name="RadiusX"><xsl:value-of select="@r" /></xsl:attribute>
-      <xsl:attribute name="RadiusY"><xsl:value-of select="@r" /></xsl:attribute>
+      <xsl:attribute name="RadiusX">
+        <xsl:value-of select="@r" />
+      </xsl:attribute>
+      <xsl:attribute name="RadiusY">
+        <xsl:value-of select="@r" />
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@rx">
+      <xsl:attribute name="RadiusX">
+        <xsl:value-of select="@rx" />
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@ry">
+      <xsl:attribute name="RadiusY">
+        <xsl:value-of select="@ry" />
+      </xsl:attribute>
     </xsl:if>
+    <xsl:apply-templates mode="transform" select=".">
+      <xsl:with-param name="mapped_type" select="'EllipseGeometry'" />
+    </xsl:apply-templates>
   </EllipseGeometry>
 </xsl:template>
 
-<!-- Geometry for rectangle -->
+<!-- 
+  // Clip Geometry for rectangle //
+-->
 <xsl:template mode="geometry" match="*[name(.) = 'rect']">
   <RectangleGeometry>
-    <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>
-    <!--
-    <xsl:if test="@x"><xsl:attribute name="Canvas.Left"><xsl:value-of select="@x" /></xsl:attribute></xsl:if>
-    <xsl:if test="@y"><xsl:attribute name="Canvas.Top"><xsl:value-of select="@y" /></xsl:attribute></xsl:if>
-    <xsl:if test="@width"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>
-    <xsl:if test="@height"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>
-    <xsl:if test="@rx"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>
-    <xsl:if test="@ry"><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>
-    -->
-    <xsl:attribute name="Rect"><xsl:value-of select="concat('0, 0, ', @width, ', ', @height)" /></xsl:attribute>
+    <xsl:if test="../@id">
+      <xsl:attribute name="x:Key">
+        <xsl:value-of select="../@id" />
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:variable name="x">
+        <xsl:call-template name="convert_unit">
+          <xsl:with-param name="convert_value" select="@x" />
+        </xsl:call-template>
+    </xsl:variable>
+    <xsl:variable name="y">
+        <xsl:call-template name="convert_unit">
+          <xsl:with-param name="convert_value" select="@y" />
+        </xsl:call-template>
+    </xsl:variable>
+    <xsl:variable name="width">
+        <xsl:call-template name="convert_unit">
+          <xsl:with-param name="convert_value" select="@width" />
+        </xsl:call-template>
+    </xsl:variable>
+    <xsl:variable name="height">
+      <xsl:call-template name="convert_unit">
+        <xsl:with-param name="convert_value" select="@height" />
+      </xsl:call-template>
+    </xsl:variable>
+    <xsl:if test="@rx">
+      <xsl:attribute name="RadiusX">
+        <xsl:value-of select="@rx" />
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@ry">
+      <xsl:attribute name="RadiusY">
+        <xsl:value-of select="@ry" />
+      </xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@rx and not(@ry)">
+      <xsl:attribute name="RadiusX">
+        <xsl:value-of select="@rx" />
+      </xsl:attribute>
+      <xsl:attribute name="RadiusY">
+        <xsl:value-of select="@rx" />
+      </xsl:attribute>
+    </xsl:if>
+    <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>
+    <xsl:attribute name="Rect"><xsl:value-of select="concat($x, ', ', $y, ', ', $width, ', ', $height)" /></xsl:attribute>
+    <xsl:apply-templates mode="transform" select=".">
+      <xsl:with-param name="mapped_type" select="'RectangleGeometry'" />
+    </xsl:apply-templates>
   </RectangleGeometry>
 </xsl:template>