[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] adding namespace node to arbitrary
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 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:
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.
Benjamin Li wrote:
Re: [xsl] adding namespace node to arbitrary - xslt 1 or 2
Subject: Re: [xsl] adding namespace node to arbitrary <xsl:element> - xslt 1 or 2 From: Abel Braaksma <abel.online@xxxxxxxxx> Date: Thu, 17 May 2007 00:50:09 +0200 |
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:
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] adding namespace node to , David Carlisle | Thread | RE: [xsl] adding namespace node to , Michael Kay |
Re: [xsl] adding namespace node to , David Carlisle | Date | RE: [xsl] adding namespace node to , Michael Kay |
Month |