Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why does XSLT insert xmlns=""?

 
Ranch Hand
Posts: 420
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following template:
<blockquote>code:
<pre name="code" class="core">
<xsl:template match="family">
<text y="100" x="200" style="font-size:20;stroke:green;fill:green;font-weight:light ">
<xsl:value-of select="@title"/>
</text>
</xsl:template>
</pre>
</blockquote>

When I perform the XSLT using xalanj 2.7.1 this produces

<blockquote>code:
<pre name="code" class="core">
<text xmlns="" style="font-size:20;stroke:green;fill:green;font-weight:light " x="200" y="100">English</text>
</pre>
</blockquote>

This extra attribute xmlns is messing up the mozilla SVG renderer! How do I suppress it?

Thanks!
Siegfried
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need to see a bit more context; presumably the default namespace on a parent element in the output is set to something else, and Xalan needs to reset it.

In any case, SVG elements are in the http://www.w3.org/2000/svg namespace, so you should be declaring that on your <text> element in your XSLT: <blockquote>code:
<pre name="code" class="core"><text xmlns="http://www.w3.org/2000/svg"; .../></pre>
</blockquote>
 
Siegfried Heintze
Ranch Hand
Posts: 420
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Progress!

This works:
<blockquote>code:
<pre name="code" class="core">
<xsl:template match="family">
<text xmlns="http://www.w3.org/2000/svg"; y="100" x="200" style="font-size:20;stroke:green;fill:green;font-weight:light ">
<xsl:value-of select="@title"/>
</text>
</xsl:template>
</pre>
</blockquote>

But this does not work because it still emits the 'xmlns=""':
<blockquote>code:
<pre name="code" class="core">
<xsl:template match="layout">
<xsl:element name="rect">
<xsl:attribute name="xmlns">http://www.w3.org/2000/svg</xsl:attribute>;
<xsl:attribute name="x"><xsl:value-of select="outline/@x"/></xsl:attribute>
<xsl:attribute name="y"><xsl:value-of select="outline/@y"/></xsl:attribute>
<xsl:attribute name="width"><xsl:value-of select="outline/@width"/></xsl:attribute>
<xsl:attribute name="height"><xsl:value-of select="outline/@height"/></xsl:attribute>
<xsl:attribute name="style">fill:none;stroke:blue;stroke-width:2</xsl:attribute>
</xsl:element>
<xsl:apply-templates />
</xsl:template>
</pre>
</blockquote>
 
Carey Evans
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The XML namespace comes from the one in effect on the XSLT document, not just by copying an attribute. An xsl:attribute isn't going to work, and the standard says as much. If you use xsl:element, you need to use the namespace attribute there.

By the way, you don't need to use xsl:element just to use xsl:attribute; your example doesn't need xsl:attribute, either, just: <blockquote>code:
<pre name="code" class="core"><rect xmlns="http://www.w3.org/2000/svg"; x="{outline/@x}" ... /></pre>
</blockquote>
 
Marshal
Posts: 25669
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The xmlns="" says that the element it's applied to is not in a namespace. If it weren't there, then the element would be in the same namespace as its parent. That's from the inheritance rules for namespaces.

So, if you don't want it to be there, then make sure that the element in question is in the same namespace as its parent.

Edit: I see Carey Evans already said that, yesterday. Sorry for the duplication.
[ July 17, 2008: Message edited by: Paul Clapham ]
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic