Re: [xsl] a very unusual namespace question

Subject: Re: [xsl] a very unusual namespace question
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 18 May 2001 09:13:11 +0100
Hi David,

> I have a stylesheet A that is outputting stylesheet B (using
> xsl:namespace-alias'ing). Stylesheet B will be matching elements
> from namespace N so it must have a namespace declaration for N. But
> the problem is that namespace N is not known at the time I construct
> A and does not appear in the input to A. I would like to pass the
> prefix and URI for N to stylesheet A as top-level parameters. How
> can I get stylesheet A to generate a namespace declaration in B from
> the parameters? Thanks!

You might be pleased to know that being able to create a namespace
node (which is what you're after here) is on the list of requirements
for XSLT 2.0... or at least is something that it *could* enable (see
Requirement 1.6 in http://www.w3.org/TR/xslt20req).

In the meantime, the trick that I use is to create a bogus namespaced
attribute on the element that you want to add the namespace node to.
It's easiest in your case to add it to the oxsl:stylesheet element
that you're creating.  So, given that you have parameters holding the
prefix and URI for the namespace:

  <xsl:param name="ns-prefix" select="'ns'" />
  <xsl:param name="ns-URI" />

You can do something like:

  <oxsl:stylesheet version="1.0">
     <xsl:attribute name="{$ns-prefix}:dummy"
                    namespace="{$ns-URI}">dummy</xsl:attribute>
     ...
  </oxsl:stylesheet>

In most processors you will then be able to use the $ns-prefix to
indicate the namespace that you're after.  The only problem is that
processors don't *have* to use the prefix you've specified when you
create the attribute:

  "XSLT processors may make use of the prefix of the QName specified
  in the name attribute when selecting the prefix used for outputting
  the created attribute as XML; however, they are not required to do
  so and, if the prefix is xmlns, they must not do so."

so it's not guaranteed (although I don't know of a processor that
doesn't).
  
I hope that helps,

Jeni

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



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


Current Thread