473,549 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing Default Namespace within XSLT Transformation


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 XslTransformExc eption is
generated:

Cannot construct namespace declaration xmlns='uri:shar edSchema'.
Prefix '' is already mapped to namespace 'uri:documentSc hema'.

The XSLT looks similar to this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:d="uri:do cumentSchema"
xmlns:s="uri:sh aredSchema">

<xsl:template match="/">
<myDocument xmlns="uri:docu mentSchema">
... Output document items ...
<d:sharedInfo xmlns="uri:shar edSchema">
... 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

Jan 2 '07 #1
4 4299
* DFB wrote in microsoft.publi c.dotnet.xml:
>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 XslTransformExc eption is
generated:

Cannot construct namespace declaration xmlns='uri:shar edSchema'.
Prefix '' is already mapped to namespace 'uri:documentSc hema'.

The XSLT looks similar to this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:d="uri:do cumentSchema"
xmlns:s="uri:sh aredSchema">

<xsl:template match="/">
<myDocument xmlns="uri:docu mentSchema">
... Output document items ...
<d:sharedInfo xmlns="uri:shar edSchema">
... 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?
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:bj****@h oehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jan 2 '07 #2
DFB wrote:
XslCompiledTran sform xsltTran = new XslCompiledTran sform();
xsltTran.Transf orm( xmlDoc, xsltArgs, xmlWriter );
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:d="uri:do cumentSchema"
xmlns:s="uri:sh aredSchema">

<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />

<xsl:template match="/">
<xsl:apply-templates select="body"/>
</xsl:template>

<xsl:template match="body">
<document xmlns="uri:docu mentSchema">
<docItems/>
<d:sharedItem s xmlns="uri:shar edSchema">
<sharedItem/>
<xsl:apply-templates/>
</d:sharedItems>
</document>
</xsl:template>

</xsl:stylesheet>
And this input XML document:

<?xml version="1.0" encoding="utf-8"?>
<body/>
I think you have hit a bug in XslCompiledTran sform.

Maybe someone of the XML teams picks this up.

Complete stack trace I get with XslCompiledTran sform and that stylesheet
and input XML documents above (simply doing Transform("inpu t.xml",
"result.xml ")):

Unhandled Exception: System.Xml.Xsl. XslTransformExc eption: Cannot
construct namespace declaration xmlns='uri:shar edSchema'. Prefix '' is
already mapped to namespace 'uri:documentSc hema'.
at
System.Xml.Xsl. Runtime.XmlQuer yOutput.WriteNa mespaceDeclarat ion(String
prefix, String ns)
at <xsl:template match="body">(X mlQueryRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator
{urn:schemas-microsoft-com:xslt-debug}current)
at <xsl:template match="/">(XmlQueryRunt ime
{urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator
{urn:schemas-microsoft-com:xslt-debug}current)
at Root(XmlQueryRu ntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Execute(XmlQuer yRuntime
{urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl. ExecuteDelegate .Invoke(XmlQuer yRuntime runtime)
at System.Xml.Xsl. XmlILCommand.Ex ecute(Object defaultDocument ,
XmlResolver dataSources, XsltArgumentLis t argumentList,
XmlSequenceWrit er results)
at System.Xml.Xsl. XmlILCommand.Ex ecute(Object defaultDocument ,
XmlResolver dataSources, XsltArgumentLis t argumentList, XmlWriter
writer, Boolean closeWriter)

at System.Xml.Xsl. XmlILCommand.Ex ecute(XmlReader contextDocument ,
XmlResolver
dataSources, XsltArgumentLis t argumentList, Stream results)
at System.Xml.Xsl. XslCompiledTran sform.Transform (String inputUri,
String resultsFile)
at Test2007010501. Test.Main(Strin g[] args)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 5 '07 #3
I posted this issue to the Visual Studio feedback web site:

https://connect.microsoft.com/Visual...dbackID=250185

Thanks for the help,
-Dave
Jan 5 '07 #4
Thanks.
This is indeed a bug in XslCompiledTran sform.

Thanks for reporting it.
Sergey

Dave F. Baskin wrote:
I posted this issue to the Visual Studio feedback web site:

https://connect.microsoft.com/Visual...dbackID=250185

Thanks for the help,
-Dave
Jan 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2685
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the...
6
2726
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a straight XML file http://www.discovertravelandtours.com/test/templates/test.xml?Location=Germany To another XML file ...
4
1751
by: TP | last post by:
Hi, I have reached a situation where I have to create small pieces of xml (around 8k characters) within my java app. Right now I am using stringbuffer to create the xml which does not go against a dtd. This is working for now, since I do not have to read in the xml again. But if I wanted to use some other xml utility like xerces or jdom,...
3
10027
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/>...
4
5229
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); } if (x) {
5
4402
by: shauldar | last post by:
Is there a way (tool, hack...) to create an XSL:FO from an XSLT + XML files? My motivation is that we want to use a tool to design reports, and from that "design" generate both HTML (via XSLT) and PDF (via XSL:FO). The only tool we have seen is Altova's StyleVision, which is very unfriendly (and uses a proprietary representation, SPS, from...
7
1835
by: Bilal | last post by:
Hello all, I came across this problem while working out the bugs in my identity trasnformation stylesheets but sidestepped it for later to see if there is an easier/better solution. This is essentially following up to my last post so apologies for repeating parts of the post. The transformation stylesheet is (after corrections from kind...
2
1485
by: Pascal | last post by:
Hello, I am beginner with XML. I have created a XML file with a DTD and a XSL stylesheet in order to view my data in HTML. It works. Then I have tried to setup a XSD instead of DTD and add few type constraints. Then I am not any more able to see correct HTML output.
5
3901
by: mahesh.nimbalkar | last post by:
When I transform XML, XSLT automatically adds extra attributes to the node which are declared in DTD (default DTD attributes) . I just want XSLT not to add these extra default attributes from DTD. See refname and shortname attributes are added to node automatically after transformation. Please let me know how to fix this. ...
0
7524
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5372
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5089
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.