0

I have a XML file having default namespace xmlns="http://www.xxxx.com/xyz" and target namespace xmlns:tns="http://www.xxxx.com/xyz" , Both need to be removed

<?xml version="1.0" encoding="UTF-8" ?>
<Root xmlns:tns="http://www.xxxx.com/xyz" xmlns="http://www.xxxx.com/xyz">
    <Header type="XXXX" purpose="Original" xmlns="">
        <ID>XXXXXX</ID>
    </Header>
</Root>

I use the below code but it doesn't remove the default namespace xmlns="http://www.xxxx.com/xyz" from the root element

   <xsl:template match="*">
    <!-- remove element prefix -->
    <xsl:element name="{local-name()}">
      <!-- process attributes -->
      <xsl:for-each select="@*">
        <!-- remove attribute prefix -->
        <xsl:attribute name="{local-name()}">
          <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:for-each>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

Can anyone help to suggest how to solve this case?

XML image for your reference

xmlns Namespace issue

1
  • Please post all relevant code as code, not pictures. Commented Aug 29, 2024 at 17:45

1 Answer 1

0

If you want to remove the default namespace then you cannot put the renamed elements back into their original namespace.

Seeing that the attributes in your example are not in a namespace (as is most often the case), I believe you could do simply:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

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

</xsl:stylesheet>

Demo here.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, I tried this logic it is not working for me. Any other ideas?
"Not working" is not a useful description of a problem. You can verify that it is working in the demo (see the added link in my answer).
Hi I tried the demo link, given logic perfectly worked in the demo link for my XML. I also tried the same logic in SOA 12c transform, it's not working in there. Strange!
I have fixed the SOA 12c Issue for removing default namespace from file output by ading keepSrcElementName="yes" to copy file activity in BPEL. Oracle Doc ID 2646315.1 for reference support.oracle.com/epmos/faces/DocContentDisplay?id=2646315.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.