There are a few more cleanup/minimization opportunities left in our
SVG, even after it has been scoured. For example, inkscape wraps all
of its text in redundant <tspan> elements, even when the parent <text>
has the same style as the sole <tspan>. We'd like to remove those, to
simplify the code and save space.
XSLT can do this. This new stylesheet can do this. We add it now, in
preparation for yet another SVG processing phase.
--- /dev/null
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ version="1.0">
+ <xsl:output method="xml" encoding="UTF-8" />
+
+ <!--
+ The first rule replaces a <tspan> inside of a <text> with its
+ contents.
+ -->
+ <xsl:template match="svg:text/svg:tspan">
+ <xsl:value-of select="text()" />
+ </xsl:template>
+
+ <!--
+ Then this rule matches everything, and copies it while applying
+ any relevant templates to its children. Either we'll hit a <tspan>
+ within a <text> and process it, or we'll hit this rule again.
+ -->
+ <xsl:template match="*|@*">
+ <xsl:copy>
+ <xsl:apply-templates select="*|@*" />
+ </xsl:copy>
+ </xsl:template>
+</xsl:stylesheet>