Groups | Blog | Home
all groups > dotnet xml > january 2007 >

dotnet xml : Changing Default Namespace within XSLT Transformation


DFB
1/1/2007 4:34:00 PM

Within an XSLT transformation, I'm trying to switch the default namespace
within a section of the generated XML document to a shared namespace.
This way, the content of this section does not have to use a prefix for
the shared namespace, thus making the document smaller and easier to read.

This worked in .NET 1.1 with no problem, but now appears to be broken in
2.0. When you try to do this, the following XslTransformException is
generated:

Cannot construct namespace declaration xmlns='uri:sharedSchema'.
Prefix '' is already mapped to namespace 'uri:documentSchema'.

The XSLT looks similar to this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="uri:documentSchema"
xmlns:s="uri:sharedSchema">

<xsl:template match="/">
<myDocument xmlns="uri:documentSchema">
... Output document items ...
<d:sharedInfo xmlns="uri:sharedSchema">
... Output shared schema items ...
... (Child items do not use a prefix) ...
</d:sharedInfo>
</myDocument>
</xsl:template>

</xsl:stylesheet>

Maybe I'm missing something. Is this error correct?

Thanks,
-Dave Baskin
Bjoern Hoehrmann
1/2/2007 10:58:15 AM
* DFB wrote in microsoft.public.dotnet.xml:
[quoted text, click to view]

Could you post a minimal yet complete transformation and a corresponding
XML document so we could try to reproduce this problem? I do not think
there is anything wrong with your transformation, so either there is
something you did not show us, or this is a bug or limitation in the
XSLT processor you are using.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
AddThis Social Bookmark Button