My problem is how to add namespace and prefix for all elements and attributes using XSLT? My xml input as is ....
<ProcessCreditMemo xmlns='CreditMemo' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <ORDER_HEADERDetails> <ORDER_HEADER> <NAME>0010185214</NAME>
to be ...
<ns0:ProcessCreditMemo xmlns='CreditMemo' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns0="http://tempuri.org/"> <ns0:ORDER_HEADERDetails> <ns0:ORDER_HEADER> <ns0:NAME>0010185214</NAME>
I need to add the prefix "ns0:" for all elements and attributes and add the namespace "xmlns: ns0 =" http://tempuri.org/ "to the heading" ProcessCreditMemo ".
I am trying to create XSLT to do this ...
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <xsl:output method="xml" encoding="UTF-8" indent="yes"/> <xsl:template match="node()|text()|@*"> <xsl:copy> <xsl:if test="local-name()='ProcessCreditMemo'"> <xsl:attribute name="xmlns" namespace="http://tempuri.org/" /> </xsl:if>
but the resulting XML duplicates the prefix with an empty value.
<ProcessCreditMemo xmlns="CreditMemo" xmlns:ns0="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ns0:xmlns="">
namespaces xslt
user1761848
source share