Why is same-document reference in SVG affected by HTML <base> tag?
Asked Answered
F

1

6

I have an HTML page with a <base> tag, also containing SVG. Same-document references such as the below within the SVG then fail:

<html>
  <head>
    <base href="http://my/server/basedir">
  </head>
  <body>
    <svg>
      <g>
        <path d="M100,100 L150,150" id="path"/>
        <text>
          <textpath xlink:href="#path"/>
        </text>
      </g>
    </svg>
  </body>
</html>

The xlink:href="#path" reference fails to resolve. This works fine without the HTML base element. It also works if I replace the href attribute on the textpath element with an absolute IRI followed by the fragment identifier.

It seems to me that SVG should treat same-document IRI's differently and independent of the HTML base. In http://www.w3.org/TR/xmlbase/#same-document it says "Dereferencing of same-document references is handled specially.", although granted that's in the context of xml:base. By the way, I played with putting an xml:base on the svg element in hopes of overriding the HTML base setting for couldn't figure out how to make that work.

Fulminant answered 26/11, 2011 at 3:4 Comment(0)
M
0

Case 1: without xml:base

Works in IE(Edge),Chrome, but not Firefox.

<html>
  <head>
    <base href="http://my/server/basedir">
  </head>
  <body>
    <svg width="300" height="300" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">
      <g>
        <path d="M100,100 L150,150" id="path"/>
        <text>
          <textpath xlink:href="#path">Hello</textpath>
        </text>
      </g>
    </svg>
  </body>
</html>

Case 2: with xml:base

Works in IE(Edge),Chrome, Firefox.

If this page url is http://my/thisfile.htm then set xml:base="http://my/thisfile.htm" on the svg tag or textpath tag.

<html>
  <head>
    <base href="http://my/server/basedir">
  </head>
  <body>
    <svg width="300" height="300" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xml:base="http://my/thisfile.htm">
      <g>
        <path d="M100,100 L150,150" id="path"/>
        <text>
          <textpath xlink:href="#path">Hello</textpath>
        </text>
      </g>
    </svg>
  </body>
</html>
Mujik answered 8/12, 2015 at 6:15 Comment(1)
xml:base is deprecated bugs.chromium.org/p/chromium/issues/detail?id=341854Cheryl

© 2022 - 2024 — McMap. All rights reserved.