question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

defs section breaks output file because of missing xlink namespace and duplicated IDs

See original GitHub issue

If I have source files using <use xlink:href="..."/> the output file gets corrupted. It is missing the xlink namespace. Alternatively the xlink:href should be converted into href which is supported in modern browsers.

e.g. the European Flag:

<svg xmlns="http://www.w3.org/2000/svg" width="810" height="540" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 810 540">
    <defs>
        <g id="d">
            <g id="b">
                <path id="a" d="M0-1l-.31.95.477.156z"/>
                <use xlink:href="#a" transform="scale(-1 1)"/>
            </g>
            <g id="c">
                <use xlink:href="#b" transform="rotate(72)"/>
                <use xlink:href="#b" transform="rotate(144)"/>
            </g>
            <use xlink:href="#c" transform="scale(-1 1)"/>
        </g>
    </defs>
    <path fill="#039" d="M0 0h810v540H0z"/>
    <g fill="#fc0" transform="matrix(30 0 0 30 405 270)">
        <use y="-6" xlink:href="#d"/>
        <use y="6" xlink:href="#d"/>
        <g id="e">
            <use x="-6" xlink:href="#d"/>
            <use xlink:href="#d" transform="rotate(-144 -2.344 -2.11)"/>
            <use xlink:href="#d" transform="rotate(144 -2.11 -2.344)"/>
            <use xlink:href="#d" transform="rotate(72 -4.663 -2.076)"/>
            <use xlink:href="#d" transform="rotate(72 -5.076 .534)"/>
        </g>
        <use xlink:href="#e" transform="scale(-1 1)"/>
    </g>
</svg>

Resulted in a : <svg xmlns="http://www.w3.org/2000/svg"> [1] missing namespace xlink error

Additionally the referenced IDs within the defs section are not rewritten/renumbered. So if multiple files contain the same ID it will also break the output file:

<defs>
  <g id="a"><path d="M0-1l-.31.95.477.156z"/></g>
  <g id="a"><rect width="5" height="1" y="2" x="0"/></g>
</defs>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
fvschcommented, Nov 30, 2016

I made a template that fixes this issue by checking if xlink:href occurs in the symbols or defs and outputting a xmlns:xlink attribute on the <svg> element in that case: https://github.com/gradientz/assets-builder/blob/master/assets-builder/tasks/svgsymbols-sprite.svg?short_path=5622458

For avoiding duplicating ids, I use gulp-svgmin to rewrite the ids:

// …
.pipe(svgmin(function(file) {
  var name = path.basename(file.relative, path.extname(file.relative))
  var ids = { cleanupIDs: { minify: true, prefix: 'def-' + name + '-' } }
  return { plugins: [ ids ] }
}))
.pipe(svgsymbols({…}))
// …
0reactions
bluemoehrecommented, Oct 12, 2016

@Hiswe Sure. Simply check all IDs which will be added together to defs section. Should be enough I think. Thx man.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline XBRL Part 1: Specification 1.1
An Inline XBRL Element is any element defined by this Specification with a namespace name which has a value of http://www.xbrl.org/2013/ ...
Read more >
EDGAR Filer Manual, Volume II
Chapter 8 (Preparing and Transmitting EDGARLink Online Submissions) of the EDGAR. Filer Manual, Volume II: “EDGAR Filing.”.
Read more >
Document Structure — SVG 2
An SVG document fragment can stand by itself as a self-contained file or resource, in which case the SVG document fragment is an...
Read more >
SSDN - Duplicate xmlns value and XML header problem
The output XML should look exactly like the output file I have uploaded in my previous post. I am attaching the screenshot of...
Read more >
Release Notes for the DocBook XSL Stylesheets - SourceForge
Add missing xlink namespace declaration to the root element. ... simple.xlink because it produces duplicate ids in the output because the element template ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found