Created
June 2, 2023 19:58
-
-
Save paul-snively/69833c2605aa09a328caec2c3865fa53 to your computer and use it in GitHub Desktop.
XSLT to transform SVG converted from PDF so it scales in an HTML5 img tag, per <https://css-tricks.com/scale-svg/>.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
xmlns='http://www.w3.org/2000/svg' | |
xmlns:svg='http://www.w3.org/2000/svg' | |
exclude-result-prefixes="xs" | |
version="1.1"> | |
<xsl:template match="svg:svg[@viewBox]"> | |
<xsl:copy> | |
<xsl:copy-of select="@*[name(.)!='height' and name(.) != 'width']" /> | |
<xsl:attribute name="height">100%</xsl:attribute> | |
<xsl:attribute name="preserveAspectRatio">xMidYMid meet</xsl:attribute> | |
<xsl:apply-templates select="node()" /> | |
</xsl:copy> | |
</xsl:template> | |
<!-- IdentityTransform --> | |
<xsl:template match="/ | @* | node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@* | node()" /> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment