[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] empty namespace declaration being generated
Subject: RE: [xsl] empty namespace declaration being generated From: "Scott Smith" <ssmith@xxxxxxxxxxxxxxxxxx> Date: Tue, 23 Jan 2007 19:22:48 -0700 |
I apologize for not seeing it in the FAQ. I did search for it before I sent the email (did again after I saw your email), but didn't find anything that looked like what I was seeing. If could give me a url, I'm happy to read it especially if after reading what's below you believe it explains the issue. Your thought about namespaces was my thought as well. However, there's only one namespace declared in the xsl file (besides the one for xsl itself). There is a mismatch in that the source file doesn't declare a namespace at all--not sure if that's significant (I'm still somewhat new to xslts). So, here's what I did. I started cutting code out of the xsl file trying to get it down to a pretty small piece that showed the problem. I think I've done that. Also, I determined that if I remove the default namespace declaration ("http://www.fred.com/somthing") from the xsl file, the problem goes away. If I leave it in, I have the problem. If the problem is that the namespaces are different between the source file (where it's non-existent) and the output file, then why is it that only one element out of everything else that is being generated gets the funky xmlns line (in the full-blown version, the input file and the transform are much larger and generate much more xml)? And, what do I do about it. I'm using the latest version (2.7.0) of xalan-c, but will be using a MS xslt library in production which I think means I'm stuck at xslt 1.0. Here's an xsl that demonstrates the problem. <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <stocks xmlns="http://www.fred.com/something"> <xsl:apply-templates select="/Info/Stock" /> </stocks> </xsl:template> <xsl:template match="Stock" /> <xsl:template match="Stock[Type/@Name='tickerSymbol']"> <security> <xsl:attribute name="exchange"> <xsl:value-of select="substring-before(Name, ':')" /> </xsl:attribute> <xsl:attribute name="ticker"> <xsl:value-of select="substring-after(Name, ':')" /> </xsl:attribute> </security> </xsl:template> </xsl:stylesheet> Here's the input (there's no namespace declaration in the source file): <?xml version="1.0" encoding="utf-8"?> <Info> <Stock> <Type Name="category" /> <Name>stocks</Name> </Stock> <Stock> <Type Name="tickerSymbol" /> <Name>NASDAQ:BMET</Name> <Description>Biomet, Inc.</Description> </Stock> <Stock> <Type Name="tickerSymbol" /> <Name>NYSE:JNJ</Name> <Description>Johnson &amp; Johnson.</Description> </Stock> </Info> The generated output file contains: <?xml version="1.0" encoding="UTF-8"?> <stocks xmlns="http://www.fred.com/something"> <security xmlns="" exchange="NASDAQ" ticker="BMET"/> <security xmlns="" exchange="NYSE" ticker="JNJ"/> </stocks> Scott -----Original Message----- From: David Carlisle [mailto:davidc@xxxxxxxxx] Sent: Tuesday, January 23, 2007 4:01 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] empty namespace declaration being generated > Has anyone seen anything like this before? yes that's why it's in the faq. You haven't shown the part of your output that is causing the xmlns="". You have generated an element in no-namespace with local name security. You have (presumably) generated a parent element in some other namespace so xslt has to add the xmlns="". <security name="ibm" /> is security in no-namespace but <foo xmlns="zzz"> <security name="ibm" /> </foo> would be security in namespace zzz so in order to output secutity in no-namespace the system has to output <foo xmlns="zzz"> <security xmlns="" name="ibm" /> </foo> to preserve the (no-)namespace of security. De[ending on hat you want, you should either generate the parent element in no-namespace to make <foo> <security name="ibm" /> </foo> or generate security in a namespace, to make <foo xmlns="zzz"> <security name="ibm" /> </foo> David
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] empty namespace declarati, David Carlisle | Thread | Re: [xsl] empty namespace declarati, David Bertoni |
RE: [xsl] empty namespace declarati, Michael Kay | Date | Re: [xsl] empty namespace declarati, David Bertoni |
Month |