Title: removing namespace in node level
Tags: node.js;xml;xslt
Question: below is my input xml code
<?xml version="1.0" encoding="UTF-8"?&gt;
<EPCISDocument xmlns:ns1="http://apse.com" schemaVersion="" creationDate=""&gt;
<EPCISHeader&gt;
<StandardBusinessDocumentHeader&gt;
<HeaderVersion/&gt;
<Sender&gt;
<Identifier Authority=""/&gt;
<ContactInformation&gt;
<Contact/&gt;
<EmailAddress/&gt;
<FaxNumber/&gt;
<TelephoneNumber/&gt;
<ContactTypeIdentifier/&gt;
</ContactInformation&gt;
</Sender&gt;
<Receiver&gt;
<Identifier Authority=""/&gt;
<ContactInformation&gt;
<Contact/&gt;
<EmailAddress/&gt;
<FaxNumber/&gt;
<TelephoneNumber/&gt;
<ContactTypeIdentifier/&gt;
</ContactInformation&gt;
</Receiver&gt;
<Manifest&gt;
<NumberOfItems/&gt;
<ManifestItem&gt;
<MimeTypeQualifierCode/&gt;
<UniformResourceIdentifier/&gt;
<Description/&gt;
<LanguageCode/&gt;
</ManifestItem&gt;
</Manifest&gt;
<BusinessScope&gt;
<Scope&gt;
<BusinessService&gt;
<BusinessServiceName/&gt;
<ServiceTransaction TypeOfServiceTransaction="" IsNonRepudiationRequired="" IsAuthenticationRequired="" IsNonRepudiationOfReceiptRequired="" IsIntegrityCheckRequired="" IsApplicationErrorResponseRequired="" TimeToAcknowledgeReceipt="" TimeToAcknowledgeAcceptance="" TimeToPerform=""/&gt;
</BusinessService&gt;
<CorrelationInformation&gt;
<RequestingDocumentCreationDateTime/&gt;
<RequestingDocumentInstanceIdentifier/&gt;
<ExpectedResponseDateTime/&gt;
</CorrelationInformation&gt;
</Scope&gt;
</BusinessScope&gt;
</StandardBusinessDocumentHeader&gt;
</EPCISHeader&gt;
<EPCISBody&gt;
<EventList&gt;
<ObjectEvent&gt;
<eventTime/&gt;
<recordTime/&gt;
<eventTimeZoneOffset/&gt;
<epcList&gt;
<epc type=""/&gt;
</epcList&gt;
<action/&gt;
<bizStep/&gt;
<disposition/&gt;
<readPoint&gt;
<id/&gt;
</readPoint&gt;
<bizLocation&gt;
<id/&gt;
</bizLocation&gt;
<bizTransactionList&gt;
<bizTransaction type=""/&gt;
</bizTransactionList&gt;
<GskEpcExtension&gt;
<manufacturingDate&gt;1234</manufacturingDate&gt;
</GskEpcExtension&gt;
</ObjectEvent&gt;
</EventList&gt;
</EPCISBody&gt;
</EPCISDocument&gt;
I want to add some prefixes, so I have applied below xslt code which got from stackoverflow and it is working fine. but with below code I am getting namespaces in node level.below is the xsl code.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:gsk="http://apse.com"&gt;
<xsl:template match="node()|@*"&gt;
<xsl:copy&gt;
<xsl:apply-templates select="node()|@*"/&gt;
</xsl:copy&gt;
</xsl:template&gt;
<xsl:template match="GskEpcExtension|GskEpcExtension//*"&gt;
<xsl:element name="gsk:{name()}" namespace="http://epcis.gsk.com"&gt;
<xsl:copy-of select="namesp75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0*"/&gt;
<xsl:apply-templates select="node()|@*"/&gt;
</xsl:element&gt;
</xsl:template&gt;
<xsl:template match="StandardBusinessDocumentHeader|StandardBusinessDocumentHeader//*"&gt;
<xsl:element name="sbdh:{name()}" namespace="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"&gt;
<xsl:copy-of select="namesp75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0*"/&gt;
<xsl:apply-templates select="node()|@*"/&gt;
</xsl:element&gt;
</xsl:template&gt;
output for this xsl code is
<?xml version="1.0" encoding="UTF-8"?&gt;
<?xml-stylesheet type="text/xsl" href="Untitled3.xslt"?&gt;
<EPCISDocument xmlns:ns1="http://apse.com" schemaVersion="" creationDate=""&gt;
<EPCISHeader&gt;
<sbdh:StandardBusinessDocumentHeader xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"&gt;
<sbdh:HeaderVersion/&gt;
<sbdh:Sender&gt;
<sbdh:Identifier Authority=""/&gt;
<sbdh:ContactInformation&gt;
<sbdh:Contact/&gt;
<sbdh:EmailAddress/&gt;
<sbdh:FaxNumber/&gt;
<sbdh:TelephoneNumber/&gt;
<sbdh:ContactTypeIdentifier/&gt;
</sbdh:ContactInformation&gt;
</sbdh:Sender&gt;
<sbdh:Receiver&gt;
<sbdh:Identifier Authority=""/&gt;
<sbdh:ContactInformation&gt;
<sbdh:Contact/&gt;
<sbdh:EmailAddress/&gt;
<sbdh:FaxNumber/&gt;
<sbdh:TelephoneNumber/&gt;
<sbdh:ContactTypeIdentifier/&gt;
</sbdh:ContactInformation&gt;
</sbdh:Receiver&gt;
<sbdh:Manifest&gt;
<sbdh:NumberOfItems/&gt;
<sbdh:ManifestItem&gt;
<sbdh:MimeTypeQualifierCode/&gt;
<sbdh:UniformResourceIdentifier/&gt;
<sbdh:Description/&gt;
<sbdh:LanguageCode/&gt;
</sbdh:ManifestItem&gt;
</sbdh:Manifest&gt;
<sbdh:BusinessScope&gt;
<sbdh:Scope&gt;
<sbdh:BusinessService&gt;
<sbdh:BusinessServiceName/&gt;
<sbdh:ServiceTransaction TypeOfServiceTransaction="" IsNonRepudiationRequired="" IsAuthenticationRequired="" IsNonRepudiationOfReceiptRequired="" IsIntegrityCheckRequired="" IsApplicationErrorResponseRequired="" TimeToAcknowledgeReceipt="" TimeToAcknowledgeAcceptance="" TimeToPerform=""/&gt;
</sbdh:BusinessService&gt;
<sbdh:CorrelationInformation&gt;
<sbdh:RequestingDocumentCreationDateTime/&gt;
<sbdh:RequestingDocumentInstanceIdentifier/&gt;
<sbdh:ExpectedResponseDateTime/&gt;
</sbdh:CorrelationInformation&gt;
</sbdh:Scope&gt;
</sbdh:BusinessScope&gt;
</sbdh:StandardBusinessDocumentHeader&gt;
</EPCISHeader&gt;
<EPCISBody&gt;
<EventList&gt;
<ObjectEvent&gt;
<eventTime/&gt;
<recordTime/&gt;
<eventTimeZoneOffset/&gt;
<epcList&gt;
<epc type=""/&gt;
</epcList&gt;
<action/&gt;
<bizStep/&gt;
<disposition/&gt;
<readPoint&gt;
<id/&gt;
</readPoint&gt;
<bizLocation&gt;
<id/&gt;
</bizLocation&gt;
<bizTransactionList&gt;
<bizTransaction type=""/&gt;
</bizTransactionList&gt;
<gsk:GskEpcExtension xmlns:gsk="http://epcis.gsk.com"&gt;
<gsk:manufacturingDate&gt;1234</gsk:manufacturingDate&gt;
</gsk:GskEpcExtension&gt;
</ObjectEvent&gt;
in the output payload for gskepcextension and standardbusinessdocuemnt header the namespaces are appearing but I need the output in below format for both nodes and the entire output structure is mentioned below. please check and help on this.
<?xml version="1.0" encoding="UTF-8"?&gt;
<epcis:EPCISDocument xmlns:epcis="urn:epcglobal:epcis:xsd:1"       xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"       xmlns:gsk="http://epcis.gsk.com" schemaVersion="1.0" creationDate="2013-05-16T13:23:36Z"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &gt;
<EPCISHeader&gt;
<sbdh:StandardBusinessDocumentHeader&gt;
<sbdh:HeaderVersion/&gt;
<sbdh:Sender&gt;
<sbdh:Identifier Authority="String"&gt;5051150024380</sbdh:Identifier&gt;
<!-- This is optional information --&gt;
<sbdh:ContactInformation&gt;
<sbdh:Contact&gt;String</sbdh:Contact&gt;
<sbdh:EmailAddress&gt;String</sbdh:EmailAddress&gt;
<sbdh:FaxNumber&gt;String</sbdh:FaxNumber&gt;
<sbdh:TelephoneNumber&gt;String</sbdh:TelephoneNumber&gt;
<sbdh:ContactTypeIdentifier&gt;String</sbdh:ContactTypeIdentifier&gt;
</sbdh:ContactInformation&gt;
</sbdh:Sender&gt;
<sbdh:Receiver&gt;
<sbdh:Identifier Authority="String"&gt;5051150018624</sbdh:Identifier&gt;
<!-- This is optional information --&gt;
<sbdh:ContactInformation&gt;
<sbdh:Contact&gt;String</sbdh:Contact&gt;
<sbdh:EmailAddress&gt;String</sbdh:EmailAddress&gt;
<sbdh:FaxNumber&gt;String</sbdh:FaxNumber&gt;
<sbdh:TelephoneNumber&gt;String</sbdh:TelephoneNumber&gt;
<sbdh:ContactTypeIdentifier&gt;String</sbdh:ContactTypeIdentifier&gt;
</sbdh:ContactInformation&gt;
</sbdh:Receiver&gt;
<sbdh:DocumentIdentification&gt;
<sbdh:Standard/&gt;
<sbdh:TypeVersion/&gt;
<sbdh:InstanceIdentifier&gt;39cf981e070111e6838b0000362219a6</sbdh:InstanceIdentifier&gt;
<sbdh:Type/&gt;
<sbdh:CreationDateAndTime&gt;2001-12-17T09:30:47Z</sbdh:CreationDateAndTime&gt;
</sbdh:DocumentIdentification&gt;
</sbdh:StandardBusinessDocumentHeader&gt;
</EPCISHeader&gt;
<EPCISBody&gt;
<EventList&gt;
<ObjectEvent&gt;
<eventTime&gt;2015-10-21T17:31:12.1530000+00:00</eventTime&gt;
<eventTimeZoneOffset&gt;+02:00</eventTimeZoneOffset&gt;
<epcList&gt;
<epc&gt;urn:epc:id:sgtin:8806500.000122.2F52DTV751</epc&gt;
<epc&gt;urn:epc:id:sgtin:8806500.000122.23037KDFCV</epc&gt;
<epc&gt;urn:epc:id:sgtin:8806500.000122.2RPZF7GAAB</epc&gt;
<epc&gt;urn:epc:id:sgtin:8806500.000122.2HSWA43EV2</epc&gt;
<epc&gt;urn:epc:id:sgtin:8806500.000122.2S0Z8P3VHV</epc&gt;
</epcList&gt;
<action&gt;ADD</action&gt;
<bizStep&gt;urn:epcglobal:cbv:bizstep:commissioning</bizStep&gt;
<disposition&gt;urn:epcglobal:cbv:disp:active</disposition&gt;
<bizLocation&gt;
<id&gt;urn:epc:id:sgln:4028685.00000.0</id&gt;
</bizLocation&gt;
<gsk:GskEpcExtension&gt;
<gsk:additionalTradeItemIdentificationValue&gt;199610</gsk:additionalTradeItemIdentificationValue&gt;
<gsk:lotNumber&gt;15L011</gsk:lotNumber&gt;
<gsk:itemExpirationDate&gt;20171006</gsk:itemExpirationDate&gt;
<gsk:manufacturingDate/&gt;
<gsk:gtin&gt;08806500001224</gsk:gtin&gt;
<gsk:nhrn&gt; </gsk:nhrn&gt;
</gsk:GskEpcExtension&gt;
</ObjectEvent&gt;
</EventList&gt;
</EPCISBody&gt;
</epcis:EPCISDocument&gt;
Comment: correct format which I need:  incorrect format which is appearing: ; in the ouput payload which does not required.

Comment: Please reduce the example to the minimum necessary to demonstrate the problem, and also explain in words what the problem is.  I have posted an answer that addresses **one** problem that I detected, but I am not going to spend my time comparing your outputs to find all the differences.


Here is another answer: It seems you only need to add one more template:
<xsl:template match="EPCISDocument"&gt;
<epcis:EPCISDocument xmlns:epcis="urn:epcglobal:epcis:xsd:1"&gt;
<xsl:apply-templates select="node()|@*"/&gt;
</epcis:EPCISDocument&gt;
</xsl:template&gt;
I would also suggest moving all your namespace declarations to the top level element, so that eventually your stylesheet looks something like:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:epcis="urn:epcglobal:epcis:xsd:1"
xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
xmlns:gsk="http://epcis.gsk.com"&gt;
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
<xsl:strip-space elements="*"/&gt;
<!-- identity transform --&gt;
<xsl:template match="@*|node()"&gt;
<xsl:copy&gt;
<xsl:apply-templates select="@*|node()"/&gt;
</xsl:copy&gt;
</xsl:template&gt;
<xsl:template match="EPCISDocument"&gt;
<epcis:EPCISDocument&gt;
<xsl:apply-templates select="node()|@*"/&gt;
</epcis:EPCISDocument&gt;
</xsl:template&gt;
<xsl:template match="GskEpcExtension|GskEpcExtension//*"&gt;
<xsl:element name="gsk:{name()}"&gt;
<xsl:apply-templates select="node()|@*"/&gt;
</xsl:element&gt;
</xsl:template&gt;
<xsl:template match="StandardBusinessDocumentHeader|StandardBusinessDocumentHeader//*"&gt;
<xsl:element name="sbdh:{name()}"&gt;
<xsl:apply-templates select="node()|@*"/&gt;
</xsl:element&gt;
</xsl:template&gt;
</xsl:stylesheet&gt;
Comment for this answer: I have applied same above xsl code, but still I am getting same output.in the nodes level I am getting the namespaces.the gskepcextnesion node should be not like    same for standard businessdocumentheader
Comment for this answer: correct format which I need:  incorrect format which is appearing  in the ouput payload which does not required.
Comment for this answer: Any suggestion on this. if the namespace is populating in the starting declarations also fine
Comment for this answer: @janardhand  I do not get the result you report, when applying the suggested change - see: http://xsltransform.net/ejivdHt  --- In any case, a redundant namespace declaration should not pose any problems for the receiving application.
Comment for this answer: As I said, I cannot reproduce the problem, so I cannot suggest a solution.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:01/05/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<node.js><xml><xslt>', 'Title': 'removing namespace in node level', 'ViewCount': 110, 'id': 41480076, 'user_AboutMe': None, 'user_AccountId': 9959802.0, 'user_DisplayName': 'janardhan d', 'user_Reputation': 35.0, 'user_Views': 36.0, 'user_id': 7369491.0}}