Re: [xsl] Setting the namespace in a document root element

Subject: Re: [xsl] Setting the namespace in a document root element
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 19 Oct 2006 11:14:59 +0200
Michael Burek wrote:

In the output document below I want the xmlns:gco="http://www.isotc211.org/2005/gco namespace declaration to appear in the MD_Metadata root element, not in the CharacterString child element(s)


[...]

<xsl:element name="MD_Metadata" >

Change this to <MD_Metadata> and remove the <xsl:namespace> instruction.



There are many CharacterString and other gco namespace elements in the real output document, so having the namespace in each is undesirable.

That's understandable, but it does not differ for any namespace aware processor.


There is a very simple trick you can employ: every non-xsl element will become a part of your literal result tree, automatically. These literal elements inherit the namespace from there parents. By defining your very first element as literal result tree element (see above), it will receive all the namespaces (and normally the same prefixes too, but that is not guaranteed) of the root xsl:stylesheet instruction. This will include the GCO namespace.

I believe this behavior is not guaranteed so in theory, but it is the way I see it happening in practice.

To suppress certain namespaces, you can employ exclude-result-prefixes on xsl:stylesheet.

HtH,

Cheers,
-- Abel Braaksma
  http://www.nuntia.com

Current Thread