[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] xslt2 - namespace attributes for output from called templates


Subject: Re: [xsl] xslt2 - namespace attributes for output from called templates
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 22 Aug 2003 14:30:14 +0100

Hi Tom,

> But if I wasn't making html, then I could have this problem. Would
> every function, called template etc. have to re-specify the
> namespace attribute?

If you want a literal result element to be in the namespace
'http://www.w3.org/1999/xhtml' then it has to be associated with that
namespace. If you don't want the element to have a prefix, then the
'http://www.w3.org/1999/xhtml' namespace has to be in-scope as the
default namespace.

Namespaces are in-scope on the element that they're declared, and on
all the descendants of that element. So the usual way in which you
guarantee that all the elements you generate in the stylesheet are in
a particular default namespace is to declare that namespace as the
default on the <xsl:stylesheet> element.

So rather than:

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

<xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
    ...
  </html>
</xsl:template>

...lots of other templates in which the default namespace is no
namespace...
                
</xsl:stylesheet>

you should use:

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

<xsl:template match="/">
  <html>
    ...
  </html>
</xsl:template>

...lots of other templates in which the default namespace is the XHTML
namespace...
                
</xsl:stylesheet>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords