tags:

views:

24

answers:

1

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&quot;&gt;
<svg width="500" height="200" version="1.1" 
    xmlns="http://www.w3.org/2000/svg&quot; 
    xmlns:xlink="http://www.w3.org/1999/xlink&quot;&gt;

    <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

A: 

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.

Erik Dahlström
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
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.
Erik Dahlström