Last active
May 30, 2023 02:58
-
-
Save ok3141/1285e56f44d7e47b9a22e664406a5fab to your computer and use it in GitHub Desktop.
Convert Android Vector Drawable to SVG with XSLT
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="ISO-8859-1"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > | |
<xsl:template match="/"> | |
<svg xmlns="http://www.w3.org/2000/svg"> | |
<xsl:attribute name="width"> | |
<xsl:value-of select="substring-before(vector/@width, 'dp')"/> | |
</xsl:attribute> | |
<xsl:attribute name="height"> | |
<xsl:value-of select="substring-before(vector/@height, 'dp')"/> | |
</xsl:attribute> | |
<xsl:attribute name="viewBox"> | |
<xsl:value-of select="concat('0 0 ', vector/@viewportWidth, ' ', vector/@viewportHeight)" /> | |
</xsl:attribute> | |
<xsl:for-each select="vector/path"> | |
<path> | |
<xsl:attribute name="fill"> | |
<xsl:value-of select="@fillColor"/> | |
</xsl:attribute> | |
<xsl:attribute name="d"> | |
<xsl:value-of select="@pathData"/> | |
</xsl:attribute> | |
</path> | |
</xsl:for-each> | |
</svg> | |
</xsl:template> | |
</xsl:stylesheet> |
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
<!-- NOTE all prefixes android: were removed manually, if someone can improve xsl, you're welcome --> | |
<vector xmlns:android="http://schemas.android.com/apk/res/android" | |
width="55dp" | |
height="55dp" | |
viewportWidth="55.0" | |
viewportHeight="55.0"> | |
<path | |
pathData="M40.5,20.5l-3,0l0,6l-19.3,0l5.3,-5.3l-2.1,-2.1l-9.2,9.2l8.9,8.9l2.1,-2.1l-5.5,-5.6l22.8,0z" | |
fillColor="#ffffff" /> | |
</vector> |
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
<svg xmlns="http://www.w3.org/2000/svg" | |
width="55" | |
height="55" | |
viewBox="0 0 55.0 55.0"> | |
<path fill="#ffffff" | |
d="M40.5,20.5l-3,0l0,6l-19.3,0l5.3,-5.3l-2.1,-2.1l-9.2,9.2l8.9,8.9l2.1,-2.1l-5.5,-5.6l22.8,0z"/> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related SO question.
Free online XSL Transformer