Re: [xsl] Empty xmlns attribute being generated

Subject: Re: [xsl] Empty xmlns attribute being generated
From: Ronan Klyne <ronan.klyne@xxxxxxxxxxx>
Date: Tue, 26 Jan 2010 09:35:13 +0000
On 26/01/2010 09:27, Mark Anderson wrote:
Hi All

I'm using XSLT1.0 and Saxon 6.5.5 (in Oxygen). I'm, transforming XML to XSL-FO to PDF. The XSL transform contains SVG.

Basically, I need to create an SVG element and then call a template several times. Each call will draw a rectangle. The problem is the<rect> element in resulting SVG has an empty xlmns element in it. See line 4 of the result

Here's a snippet from my source XSL
<fo:block>
<fo:flow flow-name="xsl-region-body">
           <fo:block>
             <fo:instream-foreign-object content-height="100">
               <svg width="400" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg";>
               <xsl:call-template name="draw_page2">
                 <xsl:with-param name="pos_across" select="1"/>
               </xsl:call-template>
               <xsl:call-template name="draw_page2">
                 <xsl:with-param name="pos_across" select="2"/>
               </xsl:call-template>
               </svg>
      </fo:instream-foreign-object>
</fo:block>

Here's the template it's calling:
<xsl:template name="draw_page2">
     <xsl:param name="width" select="70"/>
     <xsl:param name="height" select="100"/>
     <xsl:param name="pos_across" select="1"/>
     <!-- Page area -->
     <rect x="{($width * $pos_across) - $width}" y="0" width="{$width}" height="{$height}" style="stroke-width:1; fill:rgb(255,0,0); stroke:rgb(10,10,10)"/>
</xsl:template>

Here's the result:
<fo:block>
             <fo:instream-foreign-object content-height="100">
                <svg xmlns="http://www.w3.org/2000/svg"; width="400" height="100" version="1.1">
                   <rect xmlns="" x="0" y="0" width="70" height="100" style="stroke-width:1; fill:rgb(255,0,0); stroke:rgb(10,10,10)"/>
                   <rect xmlns="" x="70" y="0" width="70" height="100" style="stroke-width:1; fill:rgb(255,0,0); stroke:rgb(10,10,10)"/>
                </svg>
             </fo:instream-foreign-object>
</fo:block>

Can anyone tell me what problem is?

Your 'rect' element is in the namespace "", and the 'svg' element is in the svg namespace. The output serialiser then correctly record this in the output XML. You probably want to set xmlns="http://www.w3.org/2000/svg"; on your 'rect' element too.


Ronan

M a r k

Current Thread