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 July 16th, 2013, 02:09 PM
Registered User
 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default XSLT - xmlns namespace included in the output

I want to remove the namespace "xmlns" In my output xml generated .Please help.


Below is my Input XML :
Code:
<Sample xmlns="http://tempuri.org/Container.xsd">
  <header messageId="da44a350" location="P" containerId="" />
  <Product Ref="ZF1234567890">    
    <container_cd />
    <salesOrder />
    <salesLine />
    <width>0</width>
    <partNumber />
  </Product>
</Sample>
And my output should look like this :
Code:
<Envelope>
	<GHeader>
	<TimeStamp>2013-07-16T11:00:00</TimeStamp>
	<MessageID>da44a350</MessageID>
	</GHeader>
<Sample>
  <header messageId="da44a350" location="P" containerId="" />
  <Product Ref="ZF1234567890">    
    <container_cd />
    <salesOrder />
    <salesLine />
    <width>0</width>
    <partNumber />
  </Product>
</Sample>
</Envelope>

The XSLT I used to transform is below :
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
 exclude-result-prefixes="fo xs fn xdt my"
xmlns:my="http://tempuri.org/Container.xsd" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/my:Sample">
<xsl:message>
<Envelope>
<GHeader>
<TimeStamp>
<xsl:value-of select="format-dateTime(current-dateTime(), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')" />
</TimeStamp>
<MessageId>
<xsl:value-of select="//my:Sample/my:header/@messageId"/>
</MessageId>
</GHeader>
<xsl:element name="{name()}" namespace="{namespace-uri()}">
<xsl:copy-of select="//my:Sample/node()"/>
</Envelope>
</xsl:message>
</xsl:template>
</xsl:stylesheet>

And the Output received is :
Code:
<Envelope>
	<GHeader>
	<TimeStamp>2013-07-16T11:00:00</TimeStamp>
	<MessageID>da44a350</MessageID>
	</GHeader>
<Sample xmlns: "http:=//tempuri.org/Container.xsd">
<header messageId="da44a350" location="P" containerId="" />
  <Product Ref="ZF1234567890">    
    <container_cd />
    <salesOrder />
    <salesLine />
    <width>0</width>
    <partNumber />
  </Product>
</Sample>
</Envelope>
How do I remove the name space xmlns: "http:=//tempuri.org/Container.xsd" from the node
 
Old July 16th, 2013, 02:18 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well the input elements are in a namespace so using copy-of copies them with that namespace. You need to transform them e.g.

Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
 exclude-result-prefixes="fo xs fn xdt my"
xmlns:my="http://tempuri.org/Container.xsd" >

<xsl:template match="/">

<Envelope>
<GHeader>
<TimeStamp>
<xsl:value-of select="format-dateTime(current-dateTime(), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')" />
</TimeStamp>
<MessageId>
<xsl:value-of select="//my:Sample/my:header/@messageId"/>
</MessageId>
</GHeader>
<xsl:apply-templates/>
</Envelope>

</xsl:template>


<xsl:template match="my:*">
  <xsl:element name="{local-name()}">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>


</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
Arch82 (July 16th, 2013)
 
Old July 16th, 2013, 02:45 PM
Registered User
 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks ...It worked





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I suppress the unwanted xmlns in output john7321 XSLT 2 November 24th, 2007 05:15 PM
Included XSLT and use as object YoungLuke C# 2 October 31st, 2007 04:40 AM
Extra xmlns="" tag in output Mango_Lier XSLT 4 October 16th, 2007 11:35 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.