XSL CopyRemoveNamespace

Initial payload

This scenario is requesting to extract a node from a payload and remove all namespaces and all soap enveloppes. Sample input :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header/>
  <soap:Body>
    <DELVRY03>
      <IDOC BEGIN="1">
        <EDI_DC40 SEGMENT="1">
          <TABNAM>EDI_DC40</TABNAM>
          <MANDT>120</MANDT>
          <DOCNUM>0000000000016009</DOCNUM>
          <DOCREL>755</DOCREL>
          <STATUS>30</STATUS>
          <DIRECT>1</DIRECT>
          <OUTMOD>4</OUTMOD>
          <IDOCTYP>DELVRY03</IDOCTYP>
          <CIMTYP>DELVRY03</CIMTYP>
          <MESTYP>SHPORD</MESTYP>
          <MESCOD>ES</MESCOD>
          <MESFCT>ODS</MESFCT>
          <SNDPOR>SAPDM4</SNDPOR>
          <SNDPRT>LS</SNDPRT>
          <SNDPRN>DS4CLNT100</SNDPRN>
          <RCVPOR>MWDEV</RCVPOR>
          <RCVPRT>LS</RCVPRT>
          <RCVPFC>LS</RCVPFC>
          <RCVPRN>MWDEV1</RCVPRN>
          <CREDAT>20230426</CREDAT>
          <CRETIM>150126</CRETIM>
          <SERIAL>20230426150045</SERIAL>
        </EDI_DC40>
        <MYIDOC>
        </MYIDOC>
      </IDOC>
    </DELVRY03>
  </soap:Body>
</soap:Envelope>

Stylesheet

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="#all"
    version="3.0">
	<xsl:output omit-xml-declaration="yes" method="xml" indent="yes"/>
	<xsl:strip-space elements="*"/>
	<xsl:template match="//soap:Body">
		<xsl:apply-templates select="@*|node()" mode="copy"/>
	</xsl:template>
	<xsl:template match="@*|node()" mode="copy">
		<!-- copying  all nodes recursively-->
		<xsl:copy copy-namespaces="no">
			<xsl:copy-of select="@*" copy-namespaces="no"/>
			<xsl:apply-templates mode="copy"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>

Result

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="UTF-8"?>
<DELVRY03>
   <IDOC BEGIN="1">
      <EDI_DC40 SEGMENT="1">
         <TABNAM>EDI_DC40</TABNAM>
         <MANDT>120</MANDT>
         <DOCNUM>0000000000016009</DOCNUM>
         <DOCREL>755</DOCREL>
         <STATUS>30</STATUS>
         <DIRECT>1</DIRECT>
         <OUTMOD>4</OUTMOD>
         <IDOCTYP>DELVRY03</IDOCTYP>
         <CIMTYP>DELVRY03</CIMTYP>
         <MESTYP>SHPORD</MESTYP>
         <MESCOD>ES</MESCOD>
         <MESFCT>ODS</MESFCT>
         <SNDPOR>SAPDM4</SNDPOR>
         <SNDPRT>LS</SNDPRT>
         <SNDPRN>DS4CLNT100</SNDPRN>
         <RCVPOR>MWDEV</RCVPOR>
         <RCVPRT>LS</RCVPRT>
         <RCVPFC>LS</RCVPFC>
         <RCVPRN>MWDEV1</RCVPRN>
         <CREDAT>20230426</CREDAT>
         <CRETIM>150126</CRETIM>
         <SERIAL>20230426150045</SERIAL>
      </EDI_DC40>
      <MYIDOC/>
   </IDOC>
</DELVRY03>