[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: namespace 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.
> <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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|