Элемент <use>
копирует элемент, на который вы ссылаетесь из атрибута href
.Вы не можете указать file.svg
напрямую, вам нужно указать id
элемента.
<use xlink:href="path/to-the-file.svg#the-element"/>
// since we can't store file in StackSnippets we'll download it first
fetch('https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg')
.then(r => r.blob())
.then(b =>
// and create a blobURI, with the id of a <g> Element
use.setAttributeNS(
'http://www.w3.org/1999/xlink', 'href',
URL.createObjectURL(b) + '#g4'
)
);
<svg width="200" height="200" viewBox="0 0 900 900">
<use id="use"/>
</svg>
Но учтите, что элемент мог бы также отображать ваше изображение напрямую (даже если вы потеряете небольшой элемент управления, который у вас может быть :
<svg width="200" height="200" viewBox="0 0 200 200">
<image width="200" height="200" xlink:href="https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg"/>
</svg>