Re: AW: AW: Refinement: [xsl] creating namespaces in a generated scri pt

Subject: Re: AW: AW: Refinement: [xsl] creating namespaces in a generated scri pt
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 18 Sep 2002 15:51:32 +0100
> is well formed regarding namespaces, isn't it? ns1 and ns2 appear only in
> text nodes. The generated template uses them in the match attribute though,
> so the namespace must be declared somehow.

Ah yes sorry.

In that case the question is,
  " how do you dynamically generate namespace nodes"

which is possibly a faq and has three answers, not all of which are
usable in all circumstances, unfortunately.

1) use xslt 2 (draft) which has
that works like xsl:attribute and xsl:eleemnt and allows you to create
arbitrary namepsace nodes based on data in your source.
If you have an XSLT2 engine..

2) generate an arbitrary junk attribute in the appropriate namespce
so if $ns1 contains the namespace URI for ns1: prefix which you have
worked out from somewhere, you can add the needed namespace node to your
generated stylesheet by going
<xsl:attribute name="ns1:rubbish" namespace="{$s1}"/>
this will stick ns1:rubbish="" xmlns:ns1="....."
onto the appropriate generated XSLT element. XSLT will ignore the
attribute in the ns1 namespace but the namepsace binding will be there
for Xpath to use.
This can't be used in  other contexts where the language is strict about
which attributes are allowed.

3) use a node set extension to generate a result tree fragment containg
an element with a junk attribute as in (2) then convert to a node-set
and use <xsl:copy-of select="xx:node-set($var)/*/namespace::*/>
to copy the namespace node to the result.
this only works if you have a node-set extension function in your XSLT

Since you are generating XSLT, I'd use (2)


This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit or alternatively call
Star Internet for details on the Virus Scanning Service.

 XSL-List info and archive:

Current Thread