3

I've been trying to get XPointer URIs working in an SVG file, but haven't had any luck so far. After trying something more complicated and failing, I simplified it down to just referencing an ID. However, this still fails.

The spec seems pretty clear about this implementation:

http://www.w3.org/TR/SVG/struct.html#URIReference

I found an example online of what should be a working XPointer reference within an svg document. Here is the Original. Here is the version I copied out:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="500" height="200" version="1.1" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink">

    <defs>
        <rect id="simpleRect" width="100px" height="75px"/>
    </defs>
    <use xlink:href="#simpleRect" 
        x="50" y="50" style="fill:red"/>
    <use xlink:href="#xpointer(id('simpleRect'))" 
        x="250" y="50" style="fill:yellow"/>
</svg>

This should display two rectangles... one red and one yellow. I tried rendering with Firefox 3.6 and Inkscape 0.47. No success. Only the Red rectangle shows.

What am I missing?

Thanks for any help you can offer

2 Answers 2

2

There is currently (as of 10 March 2016, SVG 1.1 Second Edition) no support for rendering XPointers in browsers. W3Schools writes about this as follows:

XPointer Browser Support

There is no browser support for XPointer. But XPointer is used in other XML languages.

It's kind of frustrating, because all the official documentation does not bother to distinguish between browser-supported (Internet ready) features of SVG and the technically-supported, purely XML-like features of SVG.

0

From the linking section of the spec:

<URI-reference> = [ <absoluteURI> | <relativeURI> ] [ "#" <elementID> ]    -or-
<URI-reference> = [ <absoluteURI> | <relativeURI> ] [ "#xpointer(id(" <elementID> "))" ]

So what is the benefit of using xpointer syntax? All svg implementions I've seen have supported the alternative (shorter) syntax shown above (#myId). The xpointer syntax seems to be less well supported.

2
  • 1
    As I said, I eventually want to do something more complicated. XPointers allow you to use XPath queries. My example is simplest possible implementation I could come up with that still illustrates my problem.
    – Nycto
    Commented Mar 21, 2010 at 15:52
  • Right, but there is no SVG spec that specifies/requires support for full XPointer/XPath syntax. You could use XSLT if you need the XPaths, or evaluate the expressions in ecmascript instead. Both of those would likely work fine in existing SVG useragents. Commented Mar 22, 2010 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.