468,272 Members | 1,985 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Prevent xmlns decalaration in XSLT processing

I'm trying to do XML + XSLT -> Another XML. The source XML contains
multiple namespaces and XSLT will handle all possible tags under each
name space.

----source----
<document xmlns="..." xmlns:a="..." xmlns:b="">
....

----XSLT----
....
<xsl:template match="a:sometag">
....
</xsl:template>
<xsl:template match="b:sometag" />
<xsl:template match="defaultNsInSource:sometag" />
....

The problem I met is the generated xml document always contains
namespace declarations for all name spaces in source xml.

I've tried to add exclude-result-prefixes="yes" or
exclude-result-prefixes="a" in XSLT <xsl:stylesheet> tag, the later one
successfully prevent namespace "a" decalaration from generating, while
the others are still there. Even though there aren't tags under these
name spaces in result xml.

So how to prevent all namespace decalarations from generating into the
result xml?

Thanks

Jul 20 '05 #1
4 7924
Tempore 17:50:37, die Thursday 17 February 2005 AD, hinc in foro {comp.text.xml} scripsit cyclops <ji*******@gmail.com>:
I've tried to add exclude-result-prefixes="yes" or
exclude-result-prefixes="a" in XSLT <xsl:stylesheet> tag, the later one
successfully prevent namespace "a" decalaration from generating, while
the others are still there. Even though there aren't tags under these
name spaces in result xml.

So how to prevent all namespace decalarations from generating into the
result xml?


Hi,

The value of the 'exclude-result-prefixes' attribute is a whitespace seperated list of Qnames. SO in order to prevent namespaces 'a' and 'b' to be added to the result tree, use: exclude-result-prefixes="a b"
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Φιλήκοον ειναι μαλλον η Ï*ιλόλαλον" - Κλεόβουλος
Jul 20 '05 #2
"cyclops" <ji*******@gmail.com> writes:
I'm trying to do XML + XSLT -> Another XML. The source XML contains
multiple namespaces and XSLT will handle all possible tags under each
name space.

----source----
<document xmlns="..." xmlns:a="..." xmlns:b="">
...

----XSLT----
...
<xsl:template match="a:sometag">
...
</xsl:template>
<xsl:template match="b:sometag" />
<xsl:template match="defaultNsInSource:sometag" />
...

The problem I met is the generated xml document always contains
namespace declarations for all name spaces in source xml.

I've tried to add exclude-result-prefixes="yes" or
exclude-result-prefixes="a" in XSLT <xsl:stylesheet> tag, the later one
successfully prevent namespace "a" decalaration from generating, while
the others are still there. Even though there aren't tags under these
name spaces in result xml.

So how to prevent all namespace decalarations from generating into the
result xml?

Thanks


exclude-result-prefixes only affects namespaces that are used on literal
result elements in the stylesheet it has no effect on nodes copied from
the source.

The namespace nodes are being copied from your source tree, this will
not happen by default (only text nodes are copied by default) so it is a
template that you have not shown that is copying the nodes.
if you copy an element node then you always get all its namespaces, if
you don't want that, don't copy it, ie don't use xsl:copy or xsl:copy-of
use <xsl:element name="{name()}"> instead as this generates a fresh
element node with only the namespace nodes for its own namespace (if it
has one) and the xml namespace.

David
Jul 20 '05 #3


cyclops wrote:

So how to prevent all namespace decalarations from generating into the
result xml?


List all the prefixes of namespaces you want to exclude e.g.
<xsl:stylesheet
exclude-result-prefixes="a b c"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
This works fine for me now.
Once there are more and more name spaces, David's solution
(<xsl:element> tag) might be a better one.
Thank you all for quick response

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Rosa M Gmez Flores | last post: by
10 posts views Thread by Saqib Ali | last post: by
3 posts views Thread by Mike Dickens | last post: by
7 posts views Thread by Simon Hart | last post: by
reply views Thread by R. Ian Lee | last post: by
2 posts views Thread by Boris | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.