Re: [xsl] How do I force the XSLT processor to retain a namespace declaration despite an ancestor element having that same namespace declaration?

Subject: Re: [xsl] How do I force the XSLT processor to retain a namespace declaration despite an ancestor element having that same namespace declaration?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 25 Jul 2011 18:53:23 +0100
On 25/07/2011 18:05, Costello, Roger L. wrote:
Hi Folks,

When this is evaluated:

     <test xmlns:xs="http://www.w3.org/2001/XMLSchema";>
         <inner xmlns:xs="http://www.w3.org/2001/XMLSchema"; type="xs:string" />
     </test>

The output is this:

     <test xmlns:xs="http://www.w3.org/2001/XMLSchema";>
         <inner type="xs:string" />
     </test>


to back up what others have said, the serialisation of the test node is as you show, but both nodes have an associated xs namespace node, and if you copy the inner node to a different context where xs is not already in scope then the namespace declaration will be serialised.


modify your xslt so

<xsl:template match="test">
  <xsl:copy-of select="*"/>
</xsl:template>

and you will see

<inner xmlns:xs="http://www.w3.org/2001/XMLSchema"; type="xs:string" />

David


-- google plus: https:/profiles.google.com/d.p.carlisle

Current Thread