SVG Editors
List of SVG Editors: Web Based SVG Editor Direct SVG Link
http://svg-edit.googlecode.com/svn/branches/2.5.1/editor/svg-editor.html
Desktop Based Editor
2. http://inkscape.org/
3. SVG Editor and Standalone SVG Viewer.
http://www.oxygenxml.com/svg_editor.html
4. Svg Editor - Guide
http://svgeditor.7jigen.net/edit
5 . SVG Image Editor Phoenix
http://advanced.aviary.com/tools/image-editor
6. SVG Examples
http://tutorials.jenkov.com/svg/svg-examples.html
Tuesday, March 27, 2012
Monday, March 26, 2012
SVG 2 FXG Conversion Step 1
Create SVG Step 1 with the name of svg.xml
Create XSL for convert SVG to FXG Step 2 with the name of fxg.xsl : You can copy and post this code in the give file name
Step 3 Create PHP file svg2fxg.php as per below and must have enable xsl lib in php
<svg version="1.2" id="untitled" viewBox="0 0 800 600" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<line x1="169" x2="264" y1="94" y2="129" id="untitled" transform="matrix(1,0,0,1,0,0)" style="opacity:1;stroke:#1AFB3B;fill:#BC069B;fill-opacity:1;stroke-opacity:1;stroke-width:5;stroke-miterlimit:3;stroke-linecap:none;stroke-linejoin:round;"/>
</svg>
Create XSL for convert SVG to FXG Step 2 with the name of fxg.xsl : You can copy and post this code in the give file name
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://ns.adobe.com/fxg/2008"
xmlns:fxg="http://ns.adobe.com/fxg/2008"
xmlns:d="http://ns.adobe.com/fxg/2008/dt"
xmlns:exsl="http://exslt.org/common"
xmlns:math="http://exslt.org/math"
xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"
xmlns:svg="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd"
exclude-result-prefixes="rdf xlink xs exsl libxslt"
extension-element-prefixes="math">
<xsl:strip-space elements="*" />
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<!--
// Root template //
-->
<xsl:template match="/">
<xsl:apply-templates mode="forward" />
</xsl:template>
<!--
// Graphic //
First SVG element is converted to Graphic
-->
<xsl:template mode="forward" match="/*[name(.) = 'svg']" priority="1">
<Graphic>
<xsl:attribute name="version">2.0</xsl:attribute>
<xsl:if test="@width and not(contains(@width, '%'))">
<xsl:attribute name="viewWidth">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@width" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="@height and not(contains(@height, '%'))">
<xsl:attribute name="viewHeight">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@height" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="@width and not(contains(@width, '%')) and @height and not(contains(@height, '%'))">
<mask>
<Group>
<Rect>
<xsl:attribute name="width">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@width" />
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@height" />
</xsl:call-template>
</xsl:attribute>
<fill>
<SolidColor color="#ffffff" alpha="1"/>
</fill>
</Rect>
</Group>
</mask>
</xsl:if>
<xsl:apply-templates mode="forward" />
</Graphic>
</xsl:template>
<!--
// inner SVG elements //
Converted to groups
-->
<xsl:template mode="forward" match="*[name(.) = 'svg']">
<Group>
<xsl:if test="@x">
<xsl:attribute name="x">
<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="y">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@y" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="@width and not(contains(@width, '%')) and @height and not(contains(@height, '%'))">
<xsl:attribute name="maskType"><xsl:value-of select="'clip'"/></xsl:attribute>
<mask>
<Group>
<Rect>
<xsl:attribute name="width">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@width" />
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@height" />
</xsl:call-template>
</xsl:attribute>
<fill>
<SolidColor color="#ffffff" alpha="1"/>
</fill>
</Rect>
</Group>
</mask>
</xsl:if>
<xsl:apply-templates mode="forward" />
</Group>
</xsl:template>
<!--
// Resources (defs) //
* Resources ids
* Linear gradients
* Radial gradients
* Gradient stops list
* Gradient stop
* Clipping
-->
<!--
// Resources ids //
-->
<xsl:template mode="resources" match="*">
<!-- should be in-depth -->
<xsl:if test="ancestor::*[name(.) = 'defs']"><xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>
</xsl:template>
<!--
// Radial gradient //
Full convertion to FXG would require some math.
-->
<xsl:template name="radialGradient">
<xsl:param name="id" />
<xsl:for-each select="//*[@id=$id]">
<xsl:if test="@id">
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@spreadMethod">
<xsl:attribute name="spreadMethod">
<xsl:choose>
<xsl:when test="@spreadMethod = 'pad'">pad</xsl:when>
<xsl:when test="@spreadMethod = 'reflect'">reflect</xsl:when>
<xsl:when test="@spreadMethod = 'repeat'">repeat</xsl:when>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:if test="@color-interpolation">
<xsl:attribute name="interpolationMethod">
<xsl:choose>
<xsl:when test="@color-interpolation = 'linearRGB'">linearRGB</xsl:when>
<xsl:otherwise>rgb</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:if test="@gradientTransform">
<xsl:call-template name="gradient_transform">
<xsl:with-param name="transform" select="@gradientTransform" />
<xsl:with-param name="type" select="radial" />
</xsl:call-template>
</xsl:if>
<xsl:choose>
<xsl:when test="@xlink:href">
<xsl:variable name="reference_id" select="@xlink:href" />
<xsl:call-template name="gradientStops" >
<xsl:with-param name="id">
<xsl:value-of select="substring-after($reference_id, '#')" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:apply-templates mode="forward" /></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!--
// Clipping and masking//
-->
<xsl:template mode="clip" match="*">
<xsl:param name="object" />
<xsl:param name="clip_type" />
<xsl:choose>
<xsl:when test="$clip_type='clip' and @clip-path and contains(@clip-path, 'url')">
<Group>
<xsl:attribute name="maskType"><xsl:value-of select="'clip'"/></xsl:attribute>
<mask>
<Group>
<xsl:variable name="clip_id" select="substring-before(substring-after(@clip-path, 'url(#'), ')')"/>
<xsl:for-each select="//*[@id=$clip_id]">
<xsl:if test="not(@clipPathUnits) or @clipPathUnits != 'objectBoundingBox'">
<xsl:apply-templates mode="forward" />
</xsl:if>
</xsl:for-each>
</Group>
</mask>
<xsl:copy-of select="$object"/>
</Group>
</xsl:when>
<xsl:when test="$clip_type='mask' and @mask and contains(@mask, 'url')">
<Group>
<xsl:attribute name="maskType"><xsl:value-of select="'alpha'"/></xsl:attribute>
<mask>
<Group>
<xsl:variable name="mask_id" select="substring-before(substring-after(@mask, 'url(#'), ')')"/>
<xsl:for-each select="//*[@id=$mask_id]">
<xsl:if test="not(@maskUnits) or @maskUnits != 'objectBoundingBox'">
<xsl:apply-templates mode="forward" />
</xsl:if>
</xsl:for-each>
</Group>
</mask>
<xsl:copy-of select="$object"/>
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$object" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Id converter //
Removes "-" from the original id
(Not sure FXG really needs it)
-->
<xsl:template mode="id" match="*">
<xsl:if test="@id">
<xsl:attribute name="id"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>
</xsl:if>
</xsl:template>
<!--
// Decimal to hexadecimal converter //
-->
<xsl:template name="to_hex">
<xsl:param name="convert" />
<xsl:value-of select="concat(substring('0123456789ABCDEF', 1 + floor(round($convert) div 16), 1), substring('0123456789ABCDEF', 1 + round($convert) mod 16, 1))" />
</xsl:template>
<!--
// Unit to pixel converter //
Values with units (except %) are converted to pixels and rounded.
Unknown units are kept.
em, ex and % not implemented
-->
<xsl:template name="convert_unit">
<xsl:param name="convert_value" />
<xsl:choose>
<xsl:when test="contains($convert_value, 'px')">
<xsl:value-of select="round(translate($convert_value, 'px', ''))" />
</xsl:when>
<xsl:when test="contains($convert_value, 'pt')">
<xsl:value-of select="round(translate($convert_value, 'pt', '') * 1.25)" />
</xsl:when>
<xsl:when test="contains($convert_value, 'pc')">
<xsl:value-of select="round(translate($convert_value, 'pc', '') * 15)" />
</xsl:when>
<xsl:when test="contains($convert_value, 'mm')">
<xsl:value-of select="round(translate($convert_value, 'mm', '') * 3.543307)" />
</xsl:when>
<xsl:when test="contains($convert_value, 'cm')">
<xsl:value-of select="round(translate($convert_value, 'cm', '') * 35.43307)" />
</xsl:when>
<xsl:when test="contains($convert_value, 'in')">
<xsl:value-of select="round(translate($convert_value, 'in', '') * 90)" />
</xsl:when>
<xsl:when test="contains($convert_value, 'ft')">
<xsl:value-of select="round(translate($convert_value, 'ft', '') * 1080)" />
</xsl:when>
<xsl:when test="not(string(number($convert_value))='NaN')">
<xsl:value-of select="round($convert_value)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$convert_value" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Title and description //
Title is ignored and desc is converted to Tag in the mode="desc" template
-->
<xsl:template mode="forward" match="*[name(.) = 'title' or name(.) = 'desc']">
</xsl:template>
<!--
// Misc ignored stuff (markers, patterns, styles) //
-->
<xsl:template mode="forward" match="*[name(.) = 'marker' or name(.) = 'pattern' or name(.) = 'style']">
</xsl:template>
<!--
// Generic color template //
-->
<xsl:template name="template_color">
<xsl:param name="colorspec" />
<xsl:choose>
<xsl:when test="starts-with($colorspec, 'rgb(') and not(contains($colorspec , '%'))">
<xsl:value-of select="'#'" />
<xsl:call-template name="to_hex">
<xsl:with-param name="convert">
<xsl:value-of select="substring-before(substring-after($colorspec, 'rgb('), ',')" />
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="to_hex">
<xsl:with-param name="convert">
<xsl:value-of select="substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), ',')" />
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="to_hex">
<xsl:with-param name="convert">
<xsl:value-of select="substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), ')')" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($colorspec, 'rgb(') and contains($colorspec , '%')">
<xsl:value-of select="'#'" />
<xsl:call-template name="to_hex">
<xsl:with-param name="convert">
<xsl:value-of select="number(substring-before(substring-after($colorspec, 'rgb('), '%,')) * 255 div 100" />
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="to_hex">
<xsl:with-param name="convert">
<xsl:value-of select="number(substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), '%,')) * 255 div 100" />
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="to_hex">
<xsl:with-param name="convert">
<xsl:value-of select="number(substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), '%)')) * 255 div 100" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($colorspec, '#')">
<xsl:value-of select="'#'" />
<xsl:choose>
<xsl:when test="string-length(substring-after($colorspec, '#')) = 3">
<xsl:variable name="colorspec3">
<xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" />
</xsl:variable>
<xsl:value-of select="concat(substring($colorspec3, 1, 1), substring($colorspec3, 1, 1))" />
<xsl:value-of select="concat(substring($colorspec3, 2, 1), substring($colorspec3, 2, 1))" />
<xsl:value-of select="concat(substring($colorspec3, 3, 1), substring($colorspec3, 3, 1))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="named_color_hex" select="document('colors.xml')/colors/color[@name = translate($colorspec, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]/@hex" />
<xsl:choose>
<xsl:when test="$named_color_hex and $named_color_hex != ''">
<xsl:value-of select="'#'" />
<xsl:value-of select="substring-after($named_color_hex, '#')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$colorspec" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</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="alpha">
<xsl:choose>
<xsl:when test="$value < 0">0</xsl:when>
<xsl:when test="$value > 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">
<xsl:value-of select="@fill" />
</xsl:when>
<xsl:when test="@style and contains(@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, ';')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Fill" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="name(..) = 'g' or name(..) = 'svg'">
<xsl:apply-templates mode="fill" select="parent::*"/>
</xsl:when>
</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, '"', ''))" />
</xsl:if>
</xsl:template>
<!--
// Fill opacity //
-->
<xsl:template mode="fill_opacity" match="*">
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="@fill-opacity">
<xsl:value-of select="@fill-opacity" />
</xsl:when>
<xsl:when test="@style and contains(@style, 'fill-opacity:')">
<xsl:variable name="Opacity" select="substring-after(@style, 'fill-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="fill_opacity" select="parent::*" />
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$value < 0">0</xsl:when>
<xsl:when test="$value > 1">1</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Fill rule //
-->
<xsl:template mode="fill_rule" match="*">
<xsl:choose>
<xsl:when test="@fill-rule and (@fill-rule = 'nonzero' or @fill-rule = 'evenodd')">
<xsl:if test="@fill-rule = 'nonzero'">
<xsl:attribute name="winding">nonZero</xsl:attribute>
</xsl:if>
<xsl:if test="@fill-rule = 'evenodd'">
<xsl:attribute name="winding">evenOdd</xsl:attribute>
</xsl:if>
</xsl:when>
<xsl:when test="@style and contains(@style, 'fill-rule:')">
<xsl:variable name="FillRule" select="normalize-space(substring-after(@style, 'fill-rule:'))" />
<xsl:choose>
<xsl:when test="contains($FillRule, ';')">
<xsl:if test="substring-before($FillRule, ';') = 'nonzero'">
<xsl:attribute name="winding">nonZero</xsl:attribute>
</xsl:if>
<xsl:if test="substring-before($FillRule, ';') = 'evenodd'">
<xsl:attribute name="winding">evenOdd</xsl:attribute>
</xsl:if>
</xsl:when>
<xsl:when test="$FillRule = 'nonzero'">
<xsl:attribute name="winding">nonZero</xsl:attribute>
</xsl:when>
<xsl:when test=" $FillRule = 'evenodd'">
<xsl:attribute name="winding">evenOdd</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="name(..) = 'g' or name(..) = 'svg'">
<xsl:apply-templates mode="fill_rule" select="parent::*"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="winding">nonZero</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Generic fill template //
-->
<xsl:template mode="template_fill" match="*">
<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:choose>
<xsl:when test="$fill != '' and $fill != 'none' and not(starts-with($fill, 'url(#'))">
<!-- Solid color -->
<fill>
<SolidColor>
<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="alpha">
<xsl:value-of select="$fill_opacity" />
</xsl:attribute>
</SolidColor>
</fill>
</xsl:when>
<xsl:when test="$fill = 'none'">
</xsl:when>
<xsl:otherwise>
<fill>
<SolidColor color="#ffffff" alpha="1"/>
</fill>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Stroke //
-->
<xsl:template mode="stroke" match="*">
<xsl:choose>
<xsl:when test="@stroke">
<xsl:value-of select="@stroke" />
</xsl:when>
<xsl:when test="@style and contains(@style, 'stroke:')">
<xsl:variable name="Stroke" select="normalize-space(substring-after(@style, 'stroke:'))" />
<xsl:choose>
<xsl:when test="contains($Stroke, ';')">
<xsl:value-of select="substring-before($Stroke, ';')" />
</xsl:when>
<xsl:when test="$Stroke">
<xsl:value-of select="$Stroke" />
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="name(..) = 'g' or name(..) = 'svg'">
<xsl:apply-templates mode="stroke" select="parent::*"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<!--
// Stroke opacity //
-->
<xsl:template mode="stroke_opacity" match="*">
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="@stroke-opacity"><xsl:value-of select="@stroke-opacity" /></xsl:when>
<xsl:when test="@style and contains(@style, 'stroke-opacity:')">
<xsl:variable name="Opacity" select="substring-after(@style, 'stroke-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="stroke_opacity" select="parent::*" />
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$value < 0">0</xsl:when>
<xsl:when test="$value > 1">1</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Generic stroke template //
Not supported in FXG:
* stroke-dasharray
* stroke-dashoffset
-->
<xsl:template mode="template_stroke" match="*">
<xsl:variable name="stroke"><xsl:apply-templates mode="stroke" select="." /></xsl:variable>
<xsl:variable name="stroke_opacity"><xsl:apply-templates mode="stroke_opacity" select="." /></xsl:variable>
<xsl:variable name="stroke_width"><xsl:apply-templates mode="stroke_width" select="." /></xsl:variable>
<xsl:variable name="stroke_miterlimit"><xsl:apply-templates mode="stroke_miterlimit" select="." /></xsl:variable>
<xsl:variable name="stroke_linejoin"><xsl:apply-templates mode="stroke_linejoin" select="." /></xsl:variable>
<xsl:variable name="stroke_linecap"><xsl:apply-templates mode="stroke_linecap" select="." /></xsl:variable>
<!-- Solid color -->
<xsl:if test="$stroke != '' and $stroke != 'none' and not(starts-with($stroke, 'url(#'))">
<stroke>
<SolidColorStroke>
<xsl:attribute name="color">
<xsl:call-template name="template_color">
<xsl:with-param name="colorspec">
<xsl:value-of select="$stroke" />
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="alpha">
<xsl:value-of select="$stroke_opacity" />
</xsl:attribute>
<xsl:attribute name="weight">
<xsl:value-of select="$stroke_width" />
</xsl:attribute>
<xsl:if test="$stroke_miterlimit != ''">
<xsl:attribute name="miterLimit">
<xsl:value-of select="$stroke_miterlimit" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="joints">
<xsl:value-of select="$stroke_linejoin" />
</xsl:attribute>
<xsl:attribute name="caps">
<xsl:value-of select="$stroke_linecap" />
</xsl:attribute>
</SolidColorStroke>
</stroke>
</xsl:if>
</xsl:template>
<!--
// Stroke width //
-->
<xsl:template mode="stroke_width" match="*">
<xsl:choose>
<xsl:when test="@stroke-width">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value">
<xsl:value-of select="@stroke-width" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="@style and contains(@style, 'stroke-width:')">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value">
<xsl:choose>
<xsl:when test="contains(substring-after(@style, 'stroke-width:'), ';')">
<xsl:value-of select="substring-before(substring-after(@style, 'stroke-width:'), ';')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-after(@style, 'stroke-width:')" />
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="name(..) = 'g' or name(..) = 'svg'">
<xsl:apply-templates mode="stroke_width" select="parent::*"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Line object //
SVG: line, FXG: Line
-->
<xsl:template mode="forward" match="*[name(.) = 'line']">
<xsl:variable name="object">
<Line>
<xsl:if test="@x1">
<xsl:attribute name="xFrom">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@x1" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="@y1">
<xsl:attribute name="yFrom">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@y1" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="@x2">
<xsl:attribute name="xTo">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@x2" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="@y2">
<xsl:attribute name="yTo">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@y2" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates mode="object_opacity" select="." />
<xsl:apply-templates mode="id" select="." />
<xsl:apply-templates mode="template_fill" select="." />
<xsl:apply-templates mode="template_stroke" select="." />
<xsl:apply-templates mode="filter_effect" select="." />
<xsl:apply-templates mode="desc" select="." />
<xsl:apply-templates mode="forward" />
</Line>
</xsl:variable>
<xsl:variable name="clipped_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$object" />
<xsl:with-param name="clip_type" select="'clip'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="masked_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$clipped_object" />
<xsl:with-param name="clip_type" select="'mask'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:choose>
<xsl:when test="@transform">
<Group>
<xsl:call-template name="object_transform">
<xsl:with-param name="object" select="$masked_object" />
<xsl:with-param name="transform" select="@transform" />
</xsl:call-template>
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$masked_object" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Rectangle object //
SVG: rect, FXG: Rect
-->
<xsl:template mode="forward" match="*[name(.) = 'rect']">
<xsl:variable name="object">
<Rect>
<xsl:if test="@x">
<xsl:attribute name="x">
<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="y">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@y" />
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="@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:if test="@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="@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:apply-templates mode="object_opacity" select="." />
<xsl:apply-templates mode="id" select="." />
<xsl:apply-templates mode="template_fill" select="." />
<xsl:apply-templates mode="template_stroke" select="." />
<xsl:apply-templates mode="filter_effect" select="." />
<!-- <xsl:apply-templates mode="resources" select="." /> -->
<xsl:apply-templates mode="desc" select="." />
<xsl:apply-templates mode="forward" />
</Rect>
</xsl:variable>
<xsl:variable name="clipped_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$object" />
<xsl:with-param name="clip_type" select="'clip'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="masked_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$clipped_object" />
<xsl:with-param name="clip_type" select="'mask'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:choose>
<xsl:when test="@transform">
<Group>
<xsl:call-template name="object_transform">
<xsl:with-param name="object" select="$masked_object" />
<xsl:with-param name="transform" select="@transform" />
</xsl:call-template>
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$masked_object" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Path //
SVG: path, FXG: Path
Not supported by FXG:
* elliptical arc curve commands (workaround: convert to path first)
TODO:
* Implement an arc to curve convertor
-->
<xsl:template mode="forward" match="*[name(.) = 'path']">
<xsl:variable name="object">
<Path>
<!-- Path element -->
<!-- Exclude arcs in order to prevent the mxml compiler from failing -->
<xsl:if test="@d and not(contains(@d, 'a') or contains(@d, 'A'))">
<xsl:attribute name="data">
<xsl:value-of select="normalize-space(translate(@d , ',', ' '))" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates mode="fill_rule" select="." />
<xsl:apply-templates mode="object_opacity" select="." />
<xsl:apply-templates mode="id" select="." />
<!-- Child elements -->
<xsl:apply-templates mode="template_fill" select="." />
<xsl:apply-templates mode="template_stroke" select="." />
<xsl:apply-templates mode="filter_effect" select="." />
<xsl:apply-templates mode="desc" select="." />
<xsl:apply-templates mode="forward" />
</Path>
</xsl:variable>
<xsl:variable name="clipped_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$object" />
<xsl:with-param name="clip_type" select="'clip'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="masked_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$clipped_object" />
<xsl:with-param name="clip_type" select="'mask'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:choose>
<xsl:when test="@transform">
<Group>
<xsl:call-template name="object_transform">
<xsl:with-param name="object" select="$masked_object" />
<xsl:with-param name="transform" select="@transform" />
</xsl:call-template>
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$masked_object" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="contains(@d, 'a') or contains(@d, 'A')">
<xsl:comment><xsl:value-of select="'Elliptic arc command in path data not supported, please convert to path (arcs are thus converted to curves) before exporting.'" /></xsl:comment>
</xsl:if>
</xsl:template>
<!--
// Object transform //
FXG needs a separate group for each transform type in the transform attribute (scale+translate != translate+scale)
-->
<xsl:template name="object_transform">
<xsl:param name="object" />
<xsl:param name="transform" />
<xsl:variable name="values" select="normalize-space(translate($transform, ',', ' '))" />
<xsl:choose>
<xsl:when test="contains($values, ') ')">
<xsl:variable name="values2" select="substring-after($values, ') ')" />
<Group>
<xsl:choose>
<xsl:when test="contains($values2, ') ')">
<xsl:variable name="values3" select="substring-after($values2, ') ')" />
<Group>
<xsl:copy-of select="$object" />
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$object" />
</xsl:otherwise>
</xsl:choose>
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$object" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Ellipse object //
SVG: ellipse, FXG: Ellipse
-->
<xsl:template mode="forward" match="*[name(.) = 'ellipse']">
<xsl:variable name="object">
<Ellipse>
<xsl:variable name="cx">
<xsl:choose>
<xsl:when test="@cx">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@cx" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cy">
<xsl:choose>
<xsl:when test="@cy">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@cy" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="rx">
<xsl:choose>
<xsl:when test="@rx">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@rx" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ry">
<xsl:choose>
<xsl:when test="@ry">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@ry" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$rx != 0">
<xsl:attribute name="x">
<xsl:value-of select='format-number($cx - $rx, "#.#")' />
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select='format-number(2 * $rx, "#.#")' />
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="x">
<xsl:value-of select='format-number($cx, "#.#")' />
</xsl:attribute>
<xsl:attribute name="width">0</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$ry != 0">
<xsl:attribute name="y">
<xsl:value-of select='format-number($cy - $ry, "#.#")' />
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select='format-number(2 * $ry, "#.#")' />
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="y">
<xsl:value-of select='format-number($cy, "#.#")' />
</xsl:attribute>
<xsl:attribute name="height">0</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates mode="object_opacity" select="." />
<xsl:apply-templates mode="id" select="." />
<!-- Child elements -->
<xsl:apply-templates mode="template_fill" select="." />
<xsl:apply-templates mode="template_stroke" select="." />
<xsl:apply-templates mode="filter_effect" select="." />
<xsl:apply-templates mode="desc" select="." />
<xsl:apply-templates mode="forward" />
</Ellipse>
</xsl:variable>
<xsl:variable name="clipped_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$object" />
<xsl:with-param name="clip_type" select="'clip'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="masked_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$clipped_object" />
<xsl:with-param name="clip_type" select="'mask'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:choose>
<xsl:when test="@transform">
<Group>
<xsl:call-template name="object_transform">
<xsl:with-param name="object" select="$masked_object" />
<xsl:with-param name="transform" select="@transform" />
</xsl:call-template>
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$masked_object" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
// Circle object //
SVG: circle, FXG: Ellipse
-->
<xsl:template mode="forward" match="*[name(.) = 'circle']">
<xsl:variable name="object">
<Ellipse>
<xsl:variable name="cx">
<xsl:choose>
<xsl:when test="@cx">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@cx" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cy">
<xsl:choose>
<xsl:when test="@cy">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@cy" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="r">
<xsl:choose>
<xsl:when test="@r">
<xsl:call-template name="convert_unit">
<xsl:with-param name="convert_value" select="@r" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$r != 0">
<xsl:attribute name="x">
<xsl:value-of select='format-number($cx - $r, "#.#")' />
</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select='format-number($cy - $r, "#.#")' />
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select='format-number(2 * $r, "#.#")' />
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select='format-number(2 * $r, "#.#")' />
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="x">
<xsl:value-of select='format-number($cx, "#.#")' />
</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select='format-number($cy, "#.#")' />
</xsl:attribute>
<xsl:attribute name="width">0</xsl:attribute>
<xsl:attribute name="height">0</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates mode="object_opacity" select="." />
<xsl:apply-templates mode="id" select="." />
<!-- Child elements -->
<xsl:apply-templates mode="template_fill" select="." />
<xsl:apply-templates mode="template_stroke" select="." />
<xsl:apply-templates mode="filter_effect" select="." />
<xsl:apply-templates mode="desc" select="." />
<xsl:apply-templates mode="forward" />
</Ellipse>
</xsl:variable>
<xsl:variable name="clipped_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$object" />
<xsl:with-param name="clip_type" select="'clip'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="masked_object">
<xsl:apply-templates mode="clip" select="." >
<xsl:with-param name="object" select="$clipped_object" />
<xsl:with-param name="clip_type" select="'mask'" />
</xsl:apply-templates>
</xsl:variable>
<xsl:choose>
<xsl:when test="@transform">
<Group>
<xsl:call-template name="object_transform">
<xsl:with-param name="object" select="$masked_object" />
<xsl:with-param name="transform" select="@transform" />
</xsl:call-template>
</Group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$masked_object" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Step 3 Create PHP file svg2fxg.php as per below and must have enable xsl lib in php
<?php
$smlFile = 'svg.xml';
// Write the contents to the file
file_put_contents($smlFile, $_REQUEST['svgData']);
$xml = new DOMDocument;
$xml->load('svg.xml'); //load data from file
$xmlData = $xml->saveXML();
// Load the xls File in XML format
$xsl = new DOMDocument;
$xsl->load('fxg.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
//header("Content-Type: text/xml"); // Display Raw XML , you can comment this line
//echo $proc->transformToXML($xml);
echo $fxgData = $proc->transformToXML($xml);
?>
SVG2FXG | SVG 2 FXG Conversion
This blog is related to the used to convert SVG to FXG conversion
Subscribe to:
Posts (Atom)