Win a copy of Microservices Testing (Live Project) this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Why does XSLT insert xmlns=""?

 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27278
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic