summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/images/fixup-svg.xsl
blob: d6c46b362e0d144a66b3e41b899309fb1cd15d42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:svg="http://www.w3.org/2000/svg"
                version="1.0">

<!--
Transform the SVG produced by various tools, applying assorted fixups.
-->

<!--
Add viewBox attribute to svg element if not already present.  This allows the
image to scale.
-->
<xsl:template match="svg:svg">
  <xsl:copy>
    <xsl:if test="not(@viewBox)">
      <xsl:attribute name="viewBox">
        <xsl:text>0 0 </xsl:text>
        <xsl:value-of select="@width"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="@height"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<!--
Fix stroke="transparent" attribute, which is invalid SVG.
-->
<xsl:template match="@stroke[.='transparent']">
  <xsl:attribute name="stroke">none</xsl:attribute>
</xsl:template>

<!--
copy everything else
-->
<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>