XSLT rounding attributes for SVG optimization -
i need reduce numeric precision, , minimum exponent of svg attributes save space.
input:
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250"> <circle cx="125.1111" cy="125.2222" r="124.9999" fill="red"/> </svg>
output:
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250"> <circle cx="125.1" cy="125.2" r="125.0" fill="red"/> </svg>
what stylesheet achieve result?
thoughts on safety of this?
this stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="@*[.=number()]"> <xsl:attribute name="{name()}"> <xsl:value-of select="format-number(.,'#.#')"/> </xsl:attribute> </xsl:template> </xsl:stylesheet>
output:
<svg width="250" height="250" xmlns="http://www.w3.org/2000/svg"> <circle cx="125.1" cy="125.2" r="125" fill="red"></circle> </svg>
Comments
Post a Comment