Extract symbols from an sprite SVG


I recently came across a SVG sprite that had been made with svgstore and wanted to get the individual SVG files back.

I’m sure this could be done in a real programming language, but I tried and succeeded with a simple bash script.

This is so I remember the xmlstarlet incantations that I used.

Get a list of the ids:

xmlstarlet select -t -v "//*/@id" sprite.svg

Extract an SVG:

xmlstarlet select -t -c "//*[@id=\"${ID}\"]" sprite.svg

Rename symbol to svg:

xmlstarlet edit --omit-decl --rename '//*[local-name()="symbol"]' -v svg

Date: 2024-05-27

Tags:  svg  xml

Share: