[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: a very unusual namespace question

Subject: Re: a very unusual namespace question
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 18 May 2001 09:13:11 +0100
very unusual last names
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.