xsl-list
[Top] [All Lists]

Re: [xsl] adding namespace node to arbitrary <xsl:element> - xslt 1 or 2

2007-05-16 15:52:39
There's an easy solution to your problem. Not sure it works for XSLT 1.0 (I think it does), but at least it does so for XSLT 2.0. The idea is simple. As you probably know, it does not matter what prefix you choose. Now, if you choose the same namespace, but another prefix, the processor will see it as a redefinition of the namespace and will leave it like that:

   <!-- with RLE -->
   <b:test xmlns:b="http://test"; >
       <c:test xmlns:c="http://test"; />
   </b:test>

   <!-- with xsl:element -->
   <xsl:element name="b:test" xmlns:b="http://test";>
       <b:other />
       <xsl:element name="c:test" xmlns:c="http://test"; >
           <c:other />
</xsl:element> </xsl:element>


Note that this won't work with using the namespace attribute of the xsl:element instruction. But because the name attribute is a QName, you can simply redefine the namespace for it. The output will look like this:

<b:test xmlns:b="test">
  <c:test xmlns:c="test"/>
</b:test>
<b:test xmlns:b="http://test";>
  <b:other/>
  <c:test xmlns:c="http://test";>
     <c:other/>
  </c:test>
</b:test>

In this minimized example, your "inline" xml is under (and from) <c:test> where I redefined the namespace for which otherwise would equal the namespace of <b:test>. Well, it still does, but anyway, this should get you going. If you declare a namespace that is not used immediately, it may not appear on the 'root' element of your inline xml, but a little further on. But syntactically, in terms of XML, this should not matter.

HTH
Cheers,
-- Abel Braaksma


Benjamin Li wrote:
Hi,

I'm having a problem dealing with namespaces in my stylesheet.

My problem is that I have to transform a document into a result document
that contains inline xml. let me explain.

The result document is read by another java program (created by an external party), and a certain section/fragment of the result document is read as an
independent xml file, hence the term 'inline'.

The main problem is that I need to re-declare certain namespaces in this
fragment. I managed to get to this stage:


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--