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

Re: namespace inheritance

Subject: Re: namespace inheritance
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Tue, 01 Oct 2002 21:59:43 +0200
xmlns inheritance
Venkateshwar Bommineni wrote:
Hi,
 I have trouble with following xsl snippet. All child elements
inheriting namespace declaration from parent element. How can i suppress
that.

Actually, you seem to have exactly the opposite problem you belive to have.

> <Members xmlns="htp://www.foo.com/namespace/v1">
> 	<Member xmlns="">l.fname1</Member>

The "Members" element is in the namespace identified by
"htp://www.foo.com/namespace/v1", and you use the default
name space for it. Its child elements Are in no namespace,
and the processor generates XML which resets the assignment
of the default namespace to "no namespace", this is what
the xmlns="" does. This is 100% correct.
It seems you dont want to have the default namespace reset,
or equivalently, you want to have all elements in the same
namespace. If this is the case, just ensure all the elements
are created in the same namespace. The most simple way is to
declare the assignment of the default name space at the XSLT
top level and use literal result elements consistently:

 <?xml version="1.0"?>
 <xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="htp://www.foo.com/namespace/v1"/>

 <xsl:template match="/Test">
   <Members>
     <xsl:apply-templates select="People"/>	
   </Members>
 </xsl:template>	

 <xsl:template match="People">
   <xsl:for-each select="Person">
     <Member>
       <xsl:value-of select="concat(substring(LName,1,1),'.',FName)"/>
     </Member>
   </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Of course, you can still use <xsl:element>, just keep in mind
to always specify the desired namespace.

It is recommended to avoid assigning the default namespace,
there are a few unpleasant traps which can be avoided by
consistently using prefixed QNames for elements, for example
 <xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:foo="htp://www.foo.com/namespace/v1"/>

 <xsl:template match="/Test">
   <foo:Members>
     <xsl:apply-templates select="People"/>	
   </foo:Members>
 </xsl:template>	

 <xsl:template match="People">
   <xsl:for-each select="Person">
     <foo:Member>
       <xsl:value-of select="concat(substring(LName,1,1),'.',FName)"/>
     </foo:Member>
   </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

J.Pietschmann


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.