Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2010, 10:08 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default Remove empty xmlns attribute - how to?

Hi,

I have a XSLT and in the output xml there is an element with a namespace attribute xmlns="". I want to get rid of this attribute as its not needed. Any ideas?

ie. <price xmlns=""><value>10.00</value></price>


Regards,

John
 
Old June 17th, 2010, 10:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

This attribute ensures that the <price> element is in the null namespace. If the rest of your output is in a specific namespace then this probably means that you are not creating the <price> element correctly in your XSLT.

If you are not using namespaces at all in your XML then there is no harm in leaving this attribute there - to an XML parser the following are identical XML documents:

Code:
<root></root>
and

Code:
<root xmlns=""></root>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 17th, 2010, 10:24 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

This is xml XSLT. I don't want the xmlns="" on the price element. IS there anyway to fix this?


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:temp="http://schemas.fruugo.com/merchant-product" >
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="temp:merchantProductdata" >
<xsl:copy>
<xsl:apply-templates select="@*|node()" ></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="temp:prices">
<xsl:copy>
<xsl:apply-templates select="temp:price[normalize-space(temp:pricetype) = 'NORMAL']"></xsl:apply-templates>
<xsl:if test="child::temp:price[normalize-space(temp:pricetype) = 'NORMAL']">
<price xsl:exclude-result-prefixes="temp">
<pricetype>DISCOUNT</pricetype>
<value><xsl:value-of select="child::temp:price[normalize-space(temp:pricetype) = 'NORMAL']/temp:value * 0.9" ></xsl:value-of></value>
<currency><xsl:value-of select="child::temp:price[normalize-space(temp:pricetype) = 'NORMAL']/temp:currency" ></xsl:value-of></currency>
</price>
</xsl:if>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
 
Old June 17th, 2010, 10:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Presumably the reason you don't want the xmlns="" on the <price> element is that you want this element to be in the same namespace as its parent element (that is "http://schemas.fruugo.com/merchant-product") and not in the null namespace.

If you want the price element to be in this namespace, put it there, by creating it as <temp:price> rather than <price>; and the same of course for the children of <price>

Generally the principle is: think about what expanded name to give to your created elements (expanded name = uri + local name). If you put your elements in the right namespace, the namespace declarations will take care of themselves.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xmlns attribute Hari7 XSLT 2 November 18th, 2009 11:39 AM
xmlns as an attribute Neal XSLT 7 February 16th, 2009 10:38 AM
Soap Error : Attribute xmlns must be declared RatanKumar XML 0 December 4th, 2006 08:07 PM
How do I remove xmlns from transformed document? Matt Ruby XSLT 2 October 27th, 2005 08:20 AM
attribute xmlns added in included xsl Kabe XSLT 6 November 23rd, 2004 12:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.