Skip to content

Instantly share code, notes, and snippets.

@maxkoryukov
Created April 1, 2017 15:56
Show Gist options
  • Save maxkoryukov/b83af25b8d3739a698909ae648c26f93 to your computer and use it in GitHub Desktop.
Save maxkoryukov/b83af25b8d3739a698909ae648c26f93 to your computer and use it in GitHub Desktop.

Revisions

  1. maxkoryukov created this gist Apr 1, 2017.
    60 changes: 60 additions & 0 deletions cleanup-svg.xsl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet
    version="1.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:cc="http://creativecommons.org/ns#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:svg="http://www.w3.org/2000/svg"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="xsl inkscape sodipodi rdf">

    <xsl:output method="xml" encoding="utf-8" indent="no" standalone="no"/>

    <xsl:variable name="inkscape-ns" select="'http://www.inkscape.org/namespaces/inkscape'" />
    <xsl:variable name="sodipodi-ns" select="'http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd'" />
    <xsl:variable name="preserve-style" select="false()" /><!-- TODO: use as="xs:boolean", XSLT-2 -->

    <xsl:template match="@*">
    <xsl:choose>
    <xsl:when test="namespace-uri(.)=$inkscape-ns">
    </xsl:when>

    <xsl:when test="namespace-uri(.)=$sodipodi-ns">
    </xsl:when>

    <xsl:when test="local-name()='style'">
    <xsl:if test="$preserve-style">
    <xsl:copy />
    </xsl:if>
    </xsl:when>

    <xsl:otherwise>
    <xsl:copy />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template match="node()">
    <xsl:choose>
    <xsl:when test="name()='metadata'">
    </xsl:when>

    <xsl:when test="namespace-uri(.)=$inkscape-ns">
    </xsl:when>
    <xsl:when test="namespace-uri(.)=$sodipodi-ns">
    </xsl:when>

    <xsl:otherwise>
    <xsl:copy>
    <xsl:apply-templates select="* | @*"/>
    </xsl:copy>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>


    </xsl:stylesheet>