Solved: [xsl] creating namespaces in a generated scri pt

Subject: Solved: [xsl] creating namespaces in a generated scri pt
From: "Fries, Markus, fiscus GmbH, Bonn" <M.Fries@xxxxxxxxxxx>
Date: Thu, 19 Sep 2002 12:23:52 +0200
Hi, 

the 2nd solution works fine with xalan2.4, but not with xalan2.2 .

Markus

-----Ursprüngliche Nachricht-----
Von: David Carlisle [mailto:davidc@xxxxxxxxx]
Gesendet: Mittwoch, 18. September 2002 16:52
An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Betreff: Re: AW: AW: Refinement: [xsl] creating namespaces in a
generated scri pt



> 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
<xsl:namepsace
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}"/>   [ns1 is prefix, $s1
URI]
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
engine.


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

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

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

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


Current Thread