You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1KB

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:svg="http://www.w3.org/2000/svg"
  4. version="1.0">
  5. <!--
  6. Transform the SVG produced by various tools, applying assorted fixups.
  7. -->
  8. <!--
  9. Add viewBox attribute to svg element if not already present. This allows the
  10. image to scale.
  11. -->
  12. <xsl:template match="svg:svg">
  13. <xsl:copy>
  14. <xsl:if test="not(@viewBox)">
  15. <xsl:attribute name="viewBox">
  16. <xsl:text>0 0 </xsl:text>
  17. <xsl:value-of select="@width"/>
  18. <xsl:text> </xsl:text>
  19. <xsl:value-of select="@height"/>
  20. </xsl:attribute>
  21. </xsl:if>
  22. <xsl:apply-templates select="@* | node()"/>
  23. </xsl:copy>
  24. </xsl:template>
  25. <!--
  26. Fix stroke="transparent" attribute, which is invalid SVG.
  27. -->
  28. <xsl:template match="@stroke[.='transparent']">
  29. <xsl:attribute name="stroke">none</xsl:attribute>
  30. </xsl:template>
  31. <!--
  32. copy everything else
  33. -->
  34. <xsl:template match="@* | node()">
  35. <xsl:copy>
  36. <xsl:apply-templates select="@* | node()"/>
  37. </xsl:copy>
  38. </xsl:template>
  39. </xsl:stylesheet>