xmlns confusion

S

shaun roe

I'm trying to follow the recommendations for svg writing at
http://jwatt.org/svg/authoring/
and I am generating my svg with xslt. I had some problem with
namespaces, and although I think I solved it, I don't really understand
how.

My first try at writing svg introduced the svg with

<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="600px"
height="400px" viewBox="-10 -10 620 420">

and all subsequent svg (e.g. rect, circle..) elements had svg: namespace
prefixes. In order to get no errors in my editor (oXygen), I had to also
declare the svg namespace in the stylesheet header :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:svg="http://www.w3.org/2000/svg">

something about this seemed redundant so I started trimming..

eventually I have ended up with the stylesheet declaration as:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="http://www.w3.org/2000/svg">

and all my svg elements don't need prefixes any more.

Now my questions:

Is this a correct method, i.e. standards compliant, robust
What have I done? Have I changed the default namespace to svg? What's
the difference between this and using the 'base' attribute in the
stylesheet element?

I looked on the web but don't find this use of xmlns (with no namespace
element) documented.

thanks

shaun
 
M

Martin Honnen

shaun said:
eventually I have ended up with the stylesheet declaration as:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns="http://www.w3.org/2000/svg">

and all my svg elements don't need prefixes any more.

Now my questions:

Is this a correct method, i.e. standards compliant, robust
What have I done? Have I changed the default namespace to svg?

If you have the above default namespace declaration on the root element
of the stylesheet then all result elements that do not have a prefix in
their name will be in that default namespace, unless some other element
in the stylesheet clears the default namespace e.g. xmlns="" or
redefines the default namespace. So what you do is proper use and a
common use with XSLT to ensure that result elements belong to some
namespace, in this case the SVG namespace.
What's
the difference between this and using the 'base' attribute in the
stylesheet element?

What base attribute, the xml:base attribute? That is used to resolve
relative URLs but it does not define a namespace for elements.
 
J

Joe Kesselman

shaun said:
Is this a correct method, i.e. standards compliant, robust
What have I done? Have I changed the default namespace to svg?

Exactly. See reference below.
> What's
the difference between this and using the 'base' attribute in the
stylesheet element?

Completely unrelated. Base sets a base URI that relative URI references
in the document should be interpreted relative to (rather than, as would
be normal, interpreting them relative to the location the document was
actually loaded from.) Since namespace names must always be absolute URI
references, base has no effect on namespaces.
I looked on the web but don't find this use of xmlns (with no namespace
element) documented.

In the namespaces spec,
http://www.w3.org/TR/2006/REC-xml-names11-20060816/#NT-DefaultAttName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top