[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: empty namespace declaration being generated

Subject: RE: empty namespace declaration being generated
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 24 Jan 2007 12:26:15 -0000
RE:  empty namespace declaration being generated
> What I want is that all of the elements, attributes, etc. in 
> the output xml file are under the www.fred.com/something namespace.

Then all you need to do is to put them in that namespace:

<security xmlns="www.fred.com/something">

Michael Kay
http://www.saxonica.com/


>  
> 
> ________________________________
> 
> From: David Bertoni [mailto:david.bertoni@xxxxxxxxx]
> Sent: Tue 1/23/2007 7:46 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  empty namespace declaration being generated
> 
> 
> 
> Scott Smith wrote:
> > 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.
> >
> <snip>
> 
> > 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.
> 
> There is no such version of Xalan-C.  The latest version is 1.10.
> 
> > 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;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>
> >
> 
> Which is correct.  You generate a "stocks" element in the 
> result tree using
> a literal result element in your stylesheet that has a 
> namespace URI of
> "http://www.fred.com/something".  Then, you generate two "security"
> elements in the result using a literal result in in the 
> stylesheet that
> have empty namespace URIs.  To preserve the expanded name of 
> the element,
> the serialization process generates default namespace 
> declarations that
> ensure the elements have an empty namespace URI.
> 
> You need to decide exactly what you want.  If you don't want 
> the "stocks"
> element in the namespace "http://www.fred.com/something", 
> then remove the
> default namespace declaration.  If you want the "security" 
> elements in the
> same namespace as the "stocks" element, then add the default namespace
> declaration to the "security" literal result element.  If you 
> want all of
> the literal result elements in the stylesheet in the namespace
> "http://www.fred.com/something", then you can move the 
> default namespace
> declaration to the stylesheet element.
> 
> Dave

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.